whoops^2
[mir.git] / source / mircoders / localizer / basic / MirBasicAdminInterfaceLocalizer.java
index 97a3f28..4ed7d6a 100755 (executable)
@@ -34,7 +34,7 @@ import java.text.SimpleDateFormat;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.Vector;
 
 import mir.entity.Entity;
@@ -139,18 +139,19 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz
       }
     };
 
-    public void perform(EntityAdapter aUser, EntityAdapter anEntity) {
+    public void perform(EntityAdapter aUser, EntityAdapter anEntity) throws MirLocalizerExc, MirLocalizerFailure {
       Entity entity = anEntity.getEntity();
       try {
         performModification(aUser, entity);
         entity.update();
       }
       catch (Throwable t) {
+        throw new MirLocalizerFailure(t);
       }
     };
 
     protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectFailure ;
-    protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure ;
+    protected abstract void performModification(EntityAdapter aUser, Entity anEntity)  throws MirLocalizerExc, MirLocalizerFailure ;
   }
 
   public static abstract class CommentModifyingOperation extends EntityModifyingOperation {
@@ -235,6 +236,33 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz
     }
   }
 
+  protected static class SetCommentFieldsOperation extends CommentModifyingOperation {
+    private Map values;
+
+    public SetCommentFieldsOperation(String aName, String aFields[], String aValues[]) throws MirLocalizerExc {
+      super(aName);
+
+      values = new HashMap();
+
+      for (int i=0; i<aFields.length; i++)
+        values.put(aFields[i], aValues[i]);
+    }
+
+    protected boolean isAvailable(EntityComment aComment) {
+      return true;
+    }
+
+    protected void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectFailure {
+      Iterator i = values.entrySet().iterator();
+
+      while (i.hasNext()) {
+        Map.Entry entry = (Map.Entry) i.next();
+        aComment.setValueForProperty((String) entry.getKey(), (String) entry.getValue());
+      }
+    }
+  }
+
+
   protected static class ModifyCommentFieldOperation extends CommentModifyingOperation {
     private String field;
     private String value;
@@ -297,19 +325,22 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz
 
   protected static class ChangeArticleFieldOperation extends ArticleModifyingOperation {
     private String field;
-    private String oldValue;
+    private Set oldValues;
     private String newValue;
 
-    public ChangeArticleFieldOperation(String aName, String aField, String anOldValue, String aNewValue, boolean aLogOperation) {
+    public ChangeArticleFieldOperation(String aName, String aField, String anOldValues[], String aNewValue, boolean aLogOperation) {
       super(aName, aLogOperation);
 
       field = aField;
       newValue = aNewValue;
-      oldValue = anOldValue;
+      oldValues = new HashSet(Arrays.asList(anOldValues));
+    }
+    public ChangeArticleFieldOperation(String aName, String aField, String anOldValue, String aNewValue, boolean aLogOperation) {
+      this(aName, aField, new String[] {anOldValue}, aNewValue, aLogOperation);
     }
 
     protected boolean isAvailable(EntityContent anArticle) {
-      return anArticle.getValue(field) != null && anArticle.getValue(field).equals(oldValue);
+      return anArticle.getValue(field) != null && oldValues.contains(anArticle.getValue(field));
     }
 
     protected void performModification(EntityAdapter aUser, EntityContent anArticle) throws StorageObjectFailure {