001package systems.dmx.accesscontrol.migrations; 002 003import systems.dmx.core.Association; 004import systems.dmx.core.DMXObject; 005import systems.dmx.core.Topic; 006import systems.dmx.core.service.Migration; 007 008import 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 */ 018public 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 : dmx.getAllTopics()) { 032 migrateObject(topic, "topic"); 033 } 034 for (Association assoc : dmx.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(DMXObject object, String type) { 044 try { 045 objects++; 046 if (object.hasProperty("dmx.accesscontrol.owner")) { 047 // only workspaces keep the "owner" property 048 if (!object.getTypeUri().equals("dmx.workspaces.workspace")) { 049 object.removeProperty("dmx.accesscontrol.owner"); 050 ownerRemoved++; 051 } 052 } 053 if (object.hasProperty("dmx.accesscontrol.acl")) { 054 object.removeProperty("dmx.accesscontrol.acl"); 055 aclRemoved++; 056 } 057 } catch (Exception e) { 058 throw new RuntimeException("Migrating " + type + " " + object.getId() + " failed (" + object + ")", e); 059 } 060 } 061}