+
+ public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) {
+ MirAdminInterfaceLocalizer.EntityOperation operation = getArticleOperationForName(anOperation);
+
+ try {
+ EntityAdapter user = null;
+ if (aUser!=null) {
+ user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);
+ }
+
+ if (operation!=null) {
+ operation.perform(
+ user,
+ localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle));
+ }
+ }
+ catch (Throwable t) {
+ throw new MirGlobalFailure(t.getMessage(), t);
+ }
+ }
+
+ public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) {
+ MirAdminInterfaceLocalizer.EntityOperation operation = getCommentOperationForName(anOperation);
+
+ try {
+ EntityAdapter user = null;
+ if (aUser!=null) {
+ user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser);
+ }
+
+ if (operation!=null) {
+ operation.perform(
+ user,
+ localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment));
+ }
+ }
+ catch (Throwable t) {
+ throw new MirGlobalFailure(t.getMessage(), t);
+ }
+ }
+
+ private synchronized static MirAdminInterfaceLocalizer.EntityOperation
+ getArticleOperationForName(String aName) {
+ try {
+ if (articleOperations == null) {
+ articleOperations = new HashMap();
+ Iterator i = localizer().adminInterface().simpleArticleOperations().iterator();
+ while (i.hasNext()) {
+ MirAdminInterfaceLocalizer.EntityOperation operation =
+ (MirAdminInterfaceLocalizer.EntityOperation) i.next();
+ articleOperations.put(operation.getName(), operation);
+ }
+ }
+
+ return (MirAdminInterfaceLocalizer.EntityOperation) articleOperations.get(aName);
+ }
+ catch (Throwable t) {
+ throw new MirGlobalFailure(t.getMessage(), t);
+ }
+ }
+
+ private synchronized static MirAdminInterfaceLocalizer.EntityOperation
+ getCommentOperationForName(String aName) {
+ try {
+ if (commentOperations == null) {
+ commentOperations = new HashMap();
+ Iterator i = localizer().adminInterface().simpleCommentOperations().iterator();
+ while (i.hasNext()) {
+ MirAdminInterfaceLocalizer.EntityOperation operation =
+ (MirAdminInterfaceLocalizer.EntityOperation) i.next();
+ commentOperations.put(operation.getName(), operation);
+ }
+ }
+
+ return (MirAdminInterfaceLocalizer.EntityOperation) commentOperations.get(aName);
+ }
+ catch (Throwable t) {
+ throw new MirGlobalFailure(t.getMessage(), t);
+ }
+ }
+
+ public static boolean isUserLoggedIn(String anId) {
+ synchronized (loggedInUserIds) {
+ return loggedInUserIds.containsKey(anId);
+ }
+ }
+
+ public static List getLoggedInUsers() {
+ List result = new ArrayList();
+
+ synchronized (loggedInUsers) {
+ Iterator i = loggedInUsers.entrySet().iterator();
+
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ Map item = new HashMap();
+ item.put("name", entry.getKey());
+ item.put("count", entry.getValue());
+ result.add(item);
+ }
+ }
+
+ return result;
+ }
+
+ public static BundleFactory getBundleFactory() {
+ return bundleFactory;
+ }
+
+ public static void registerLogin(String aName, String anId) {
+ modifyLoggedInCount(aName, anId, 1);
+ }
+
+ public static void registerLogout(String aName, String anId) {
+ modifyLoggedInCount(aName, anId, -1);
+ }
+
+ private static void modifyLoggedInCount(String aName, String anId, int aModifier) {
+ synchronized (loggedInUsers) {
+ Integer count = (Integer) loggedInUsers.get(aName);
+ if (count==null)
+ count = new Integer(0);
+
+ if (count.intValue()+aModifier<=0) {
+ loggedInUsers.remove(aName);
+ }
+ else {
+ loggedInUsers.put(aName, new Integer(count.intValue() + aModifier));
+ }
+ }
+
+ synchronized (loggedInUserIds) {
+ Integer count = (Integer) loggedInUserIds.get(anId);
+ if (count==null)
+ count = new Integer(0);
+
+ if (count.intValue()+aModifier<=0) {
+ loggedInUserIds.remove(anId);
+ }
+ else {
+ loggedInUserIds.put(anId, new Integer(count.intValue() + aModifier));
+ }
+ }
+ }
+
+ /**
+ * Called whenever a modifying admin action occurs. Used to log
+ * the action, if admin activity logging is turned on,
+ */
+ public static void logAdminUsage(EntityUsers aUser, String anObject, String aDescription) {
+ try {
+ if (config().getString("Mir.Admin.LogAdminActivity", "0").equals("1")) {
+ String user = "unknown (" + aUser.toString() + ")";
+ if (aUser != null)
+ user = aUser.getFieldValue("login");
+ adminUsageLogger.info(user + " | " + anObject + " | " + aDescription);
+ }
+ }
+ catch (Throwable t) {
+ logger.error("Error while logging admin usage ("+
+ aUser.toString()+", "+aDescription+"): " +t.toString());
+ }
+ }
+
+ /**
+ * Reloads all reloadable configurations, such as the producer subsystem.
+ */
+ public static void reloadConfigurations() throws MirGlobalExc, MirGlobalFailure {
+ getProducerEngine().reloadConfiguration();
+ try {
+ LoggerEngine.reload();
+ }
+ catch (Throwable e) {
+ throw new MirGlobalFailure(e);
+ }
+ getBundleFactory().reload();
+ }