001    package de.deepamehta.plugins.accesscontrol.migrations;
002    
003    import de.deepamehta.core.Association;
004    import de.deepamehta.core.DeepaMehtaObject;
005    import de.deepamehta.core.Topic;
006    import de.deepamehta.core.service.Migration;
007    
008    import java.util.logging.Logger;
009    
010    
011    
012    /**
013     * Removes "owner" and "acl" properties.
014     * Runs only in UPDATE mode.
015     * <p>
016     * Part of DM 4.5
017     */
018    public class Migration6 extends Migration {
019    
020        // ---------------------------------------------------------------------------------------------- Instance Variables
021    
022        private long objects = 0, ownerRemoved = 0, aclRemoved = 0;
023    
024        private Logger logger = Logger.getLogger(getClass().getName());
025    
026        // -------------------------------------------------------------------------------------------------- Public Methods
027    
028        @Override
029        public void run() {
030            logger.info("########## Removing owner and acl properties");
031            for (Topic topic : dms.getAllTopics()) {
032                migrateObject(topic, "topic");
033            }
034            for (Association assoc : dms.getAllAssociations()) {
035                migrateObject(assoc, "association");
036            }
037            logger.info("########## Removing owner and acl properties complete.\n    Objects processed: " + objects +
038                "\n    Owner properties removed: " + ownerRemoved + "\n    ACL properties removed: " + aclRemoved);
039        }
040    
041        // ------------------------------------------------------------------------------------------------- Private Methods
042    
043        private void migrateObject(DeepaMehtaObject object, String type) {
044            try {
045                objects++;
046                if (object.hasProperty("dm4.accesscontrol.owner")) {
047                    // only workspaces keep the "owner" property
048                    if (!object.getTypeUri().equals("dm4.workspaces.workspace")) {
049                        object.removeProperty("dm4.accesscontrol.owner");
050                        ownerRemoved++;
051                    }
052                }
053                if (object.hasProperty("dm4.accesscontrol.acl")) {
054                    object.removeProperty("dm4.accesscontrol.acl");
055                    aclRemoved++;
056                }
057            } catch (Exception e) {
058                throw new RuntimeException("Migrating " + type + " " + object.getId() + " failed (" + object + ")", e);
059            }
060        }
061    }