diff --git a/microscopy-migration-tool/src/ethz/ch/Main.java b/microscopy-migration-tool/src/ethz/ch/Main.java index 12ef35dffccc0da8eddb91138d6eb02e8e1fb94f..30b1643c7e8527be582d31274e12f23a9bc8276b 100644 --- a/microscopy-migration-tool/src/ethz/ch/Main.java +++ b/microscopy-migration-tool/src/ethz/ch/Main.java @@ -194,6 +194,10 @@ public class Main total++; System.out.println("[DONE] " + config.getTypeCode() + "\t" + total + "/" + experiments.getTotalCount()); } + // Delete old experiment type + MasterdataHelper.deleteExperimentType(sessionToken, v3, config.getTypeCode()); + // Delete old name property from new sample type + config.getSamplePropertyDelete().deleteOldPropertyType(sessionToken, v3); } System.out.println("4. Translate Properties to Samples"); @@ -234,6 +238,8 @@ public class Main total++; System.out.println("[DONE] " + config.getOldSampleTypeCode() + "\t" + total + "/" + samples.getTotalCount()); } + // Delete old copied property that become a sample + config.getEntityPropertyDelete().deleteOldPropertyType(sessionToken, v3); } System.out.println("5. Copy Property A to Property B on Samples and DataSets"); @@ -259,6 +265,8 @@ public class Main for (EntityPropertyCopy config:propertyCopiesMigrationConfig) { config.copy(sessionToken, v3); + // Delete old copied name property + config.getEntityPropertyDelete().deleteOldPropertyType(sessionToken, v3); } } } diff --git a/microscopy-migration-tool/src/ethz/ch/MasterdataHelper.java b/microscopy-migration-tool/src/ethz/ch/MasterdataHelper.java index 03bc5663b0d4a345b64626401246beec491fd9e4..e5fe6562da9410e463ce44ffa1817ca21ed89e4c 100644 --- a/microscopy-migration-tool/src/ethz/ch/MasterdataHelper.java +++ b/microscopy-migration-tool/src/ethz/ch/MasterdataHelper.java @@ -8,10 +8,12 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSetType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.create.DataSetTypeCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions.DataSetTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.update.DataSetTypeUpdate; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind; import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.EntityTypePermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id.IEntityTypeId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.ExperimentType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.create.ExperimentTypeCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.delete.ExperimentTypeDeletionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.fetchoptions.ExperimentTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.experiment.search.ExperimentTypeSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.DataType; @@ -19,7 +21,9 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.create.PropertyAssignmentCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.create.PropertyTypeCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.delete.PropertyTypeDeletionOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.fetchoptions.PropertyTypeFetchOptions; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyAssignmentPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyTypePermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.search.PropertyTypeSearchCriteria; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.SampleType; @@ -184,30 +188,69 @@ public class MasterdataHelper // Update // - public static void updateSampleType(String sessionToken, IApplicationServerApi v3, String typeCode, int addOrder, String addPropertyTypeCode) { + public enum PropertyTypeUpdateAction { ADD, REMOVE} + + public static void updateSampleType(String sessionToken, IApplicationServerApi v3, String typeCode, PropertyTypeUpdateAction updateAction, int addOrder, String addPropertyTypeCode) { SampleTypeUpdate update = new SampleTypeUpdate(); update.setTypeId(new EntityTypePermId(typeCode)); - ListUpdateValue.ListUpdateActionAdd add = new ListUpdateValue.ListUpdateActionAdd(); - PropertyAssignmentCreation propertyAssignmentCreation = new PropertyAssignmentCreation(); - propertyAssignmentCreation.setOrdinal(addOrder); - propertyAssignmentCreation.setPropertyTypeId(new PropertyTypePermId(addPropertyTypeCode)); - add.setItems(Arrays.asList(propertyAssignmentCreation)); - update.setPropertyAssignmentActions(Arrays.asList(add)); + ListUpdateValue.ListUpdateAction action = null; + switch (updateAction) { + case ADD: + action = new ListUpdateValue.ListUpdateActionAdd(); + PropertyAssignmentCreation propertyAssignmentCreation = new PropertyAssignmentCreation(); + propertyAssignmentCreation.setOrdinal(addOrder); + propertyAssignmentCreation.setPropertyTypeId(new PropertyTypePermId(addPropertyTypeCode)); + action.setItems(Arrays.asList(propertyAssignmentCreation)); + break; + case REMOVE: + action = new ListUpdateValue.ListUpdateActionRemove(); + action.setItems(Arrays.asList(new PropertyAssignmentPermId(new EntityTypePermId(typeCode, EntityKind.SAMPLE), new PropertyTypePermId(addPropertyTypeCode)))); + update.getPropertyAssignments().setForceRemovingAssignments(true); + break; + } + update.setPropertyAssignmentActions(Arrays.asList(action)); v3.updateSampleTypes(sessionToken, Arrays.asList(update)); } - public static void updateDataSetType(String sessionToken, IApplicationServerApi v3, String typeCode, int addOrder, String addPropertyTypeCode) { + public static void updateDataSetType(String sessionToken, IApplicationServerApi v3, String typeCode, PropertyTypeUpdateAction updateAction, int addOrder, String addPropertyTypeCode) { DataSetTypeUpdate update = new DataSetTypeUpdate(); update.setTypeId(new EntityTypePermId(typeCode)); - ListUpdateValue.ListUpdateActionAdd add = new ListUpdateValue.ListUpdateActionAdd(); - PropertyAssignmentCreation propertyAssignmentCreation = new PropertyAssignmentCreation(); - propertyAssignmentCreation.setOrdinal(addOrder); - propertyAssignmentCreation.setPropertyTypeId(new PropertyTypePermId(addPropertyTypeCode)); - add.setItems(Arrays.asList(propertyAssignmentCreation)); - update.setPropertyAssignmentActions(Arrays.asList(add)); + ListUpdateValue.ListUpdateAction action = null; + switch (updateAction) { + case ADD: + action = new ListUpdateValue.ListUpdateActionAdd(); + PropertyAssignmentCreation propertyAssignmentCreation = new PropertyAssignmentCreation(); + propertyAssignmentCreation.setOrdinal(addOrder); + propertyAssignmentCreation.setPropertyTypeId(new PropertyTypePermId(addPropertyTypeCode)); + action.setItems(Arrays.asList(propertyAssignmentCreation)); + break; + case REMOVE: + action = new ListUpdateValue.ListUpdateActionRemove(); + action.setItems(Arrays.asList(new PropertyAssignmentPermId(new EntityTypePermId(typeCode, EntityKind.DATA_SET), new PropertyTypePermId(addPropertyTypeCode)))); + update.getPropertyAssignments().setForceRemovingAssignments(true); + break; + } + + update.setPropertyAssignmentActions(Arrays.asList(action)); v3.updateDataSetTypes(sessionToken, Arrays.asList(update)); } + // + // Delete + // + + public static void deletePropertyType(String sessionToken, IApplicationServerApi v3, String propertyTypeCode) { + PropertyTypeDeletionOptions propertyTypeDeletionOptions = new PropertyTypeDeletionOptions(); + propertyTypeDeletionOptions.setReason("Microscopy Migration"); + v3.deletePropertyTypes(sessionToken, Arrays.asList(new PropertyTypePermId(propertyTypeCode)), propertyTypeDeletionOptions); + } + + public static void deleteExperimentType(String sessionToken, IApplicationServerApi v3, String typeCode) { + ExperimentTypeDeletionOptions experimentTypeDeletionOptions = new ExperimentTypeDeletionOptions(); + experimentTypeDeletionOptions.setReason("Microscopy Migration"); + v3.deleteExperimentTypes(sessionToken, Arrays.asList(new EntityTypePermId(typeCode, EntityKind.EXPERIMENT)), experimentTypeDeletionOptions); + } + // // Type to translate Attachments to DataSets // diff --git a/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyCopy.java b/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyCopy.java index 03b180618f530228f5c54c5901e57b6fa81d0eb3..cf3f8f8d3fc75e2fa79f54c4f75587e36d15dcf4 100644 --- a/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyCopy.java +++ b/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyCopy.java @@ -6,6 +6,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSet; import ethz.ch.MasterdataHelper; import ethz.ch.MetadataHelper; import ethz.ch.property.EntityPropertyCopy; +import ethz.ch.property.EntityPropertyDelete; import java.util.List; @@ -22,7 +23,7 @@ public class DataSetPropertyCopy extends EntityPropertyCopy<DataSet> { @Override public void updatePropertyAssignmentsHolder(String sessionToken, IApplicationServerApi v3) { - MasterdataHelper.updateDataSetType(sessionToken, v3, typeCode, 1, newPropertyCode); + MasterdataHelper.updateDataSetType(sessionToken, v3, typeCode, MasterdataHelper.PropertyTypeUpdateAction.ADD,1, newPropertyCode); } @Override @@ -34,4 +35,9 @@ public class DataSetPropertyCopy extends EntityPropertyCopy<DataSet> { public void updateEntityProperty(String sessionToken, IApplicationServerApi v3, DataSet entity) { MetadataHelper.updateDataSetProperty(sessionToken, v3, entity.getPermId().getPermId(), newPropertyCode, entity.getProperty(oldPropertyCode)); } + + @Override + public EntityPropertyDelete getEntityPropertyDelete() { + return new DataSetPropertyDelete(typeCode, oldPropertyCode); + } } diff --git a/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyDelete.java b/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyDelete.java new file mode 100644 index 0000000000000000000000000000000000000000..b63a91ca3266c0c6c97c057b64a64b2bf53c33a0 --- /dev/null +++ b/microscopy-migration-tool/src/ethz/ch/dataset/DataSetPropertyDelete.java @@ -0,0 +1,31 @@ +package ethz.ch.dataset; + +import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.DataSetType; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment; +import ethz.ch.MasterdataHelper; +import ethz.ch.property.EntityPropertyDelete; + +public class DataSetPropertyDelete extends EntityPropertyDelete { + + public DataSetPropertyDelete(String typeCode, String propertyCode) { + super(typeCode, propertyCode); + } + + @Override + public void deleteOldPropertyType(String sessionToken, IApplicationServerApi v3) { + DataSetType type = MasterdataHelper.getDataSetType(sessionToken, v3, typeCode); + boolean found = false; + for(PropertyAssignment propertyAssignment:type.getPropertyAssignments()) { + found = propertyAssignment.getPropertyType().getCode().equals(propertyCode); + if (found) { + break; + } + } + if (found) { + MasterdataHelper.updateDataSetType(sessionToken, v3, typeCode, MasterdataHelper.PropertyTypeUpdateAction.REMOVE, 1, propertyCode); + MasterdataHelper.deletePropertyType(sessionToken, v3, propertyCode); + System.out.println("[PROPERTY DELETE] " + "\t" + propertyCode); + } + } +} diff --git a/microscopy-migration-tool/src/ethz/ch/experiment/ExperimentType2SampleType.java b/microscopy-migration-tool/src/ethz/ch/experiment/ExperimentType2SampleType.java index a2d8988776efed0dac4955e18c34425dc6bf543b..bcea5c9d60b3d4d16482a6c9f87abc57a848fde8 100644 --- a/microscopy-migration-tool/src/ethz/ch/experiment/ExperimentType2SampleType.java +++ b/microscopy-migration-tool/src/ethz/ch/experiment/ExperimentType2SampleType.java @@ -1,5 +1,7 @@ package ethz.ch.experiment; +import ethz.ch.sample.SamplePropertyDelete; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -33,8 +35,7 @@ public class ExperimentType2SampleType { return propertyTypesFromTo; } - public List<String> getPropertyTypesToDeleteAfterMigration() - { - return propertyTypesToDeleteAfterMigration; + public SamplePropertyDelete getSamplePropertyDelete() { + return new SamplePropertyDelete(typeCode, propertyTypesToDeleteAfterMigration.get(0)); } } \ No newline at end of file diff --git a/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyCopy.java b/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyCopy.java index b4232ed199837fab316cc33c60d6435bf92b75b4..4533086b38cd052af2f546f74240587fa1a1531c 100644 --- a/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyCopy.java +++ b/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyCopy.java @@ -8,9 +8,9 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment; import java.util.List; public abstract class EntityPropertyCopy<ENTITY extends IPermIdHolder & IPropertiesHolder> { - protected String typeCode; - protected String oldPropertyCode; - protected String newPropertyCode; + protected final String typeCode; + protected final String oldPropertyCode; + protected final String newPropertyCode; public EntityPropertyCopy(String typeCode, String oldPropertyCode, String newPropertyCode) { this.typeCode = typeCode; @@ -18,6 +18,18 @@ public abstract class EntityPropertyCopy<ENTITY extends IPermIdHolder & IPropert this.newPropertyCode = newPropertyCode; } + public String getTypeCode() { + return typeCode; + } + + public String getOldPropertyCode() { + return oldPropertyCode; + } + + public String getNewPropertyCode() { + return newPropertyCode; + } + public abstract IPropertyAssignmentsHolder getPropertyAssignmentsHolder(String sessionToken, IApplicationServerApi v3); public abstract void updatePropertyAssignmentsHolder(String sessionToken, IApplicationServerApi v3); @@ -26,6 +38,8 @@ public abstract class EntityPropertyCopy<ENTITY extends IPermIdHolder & IPropert public abstract void updateEntityProperty(String sessionToken, IApplicationServerApi v3, ENTITY entity); + public abstract EntityPropertyDelete getEntityPropertyDelete(); + public void copy(String sessionToken, IApplicationServerApi v3) { // Is Property B assigned to the type? If not Do System.out.println("5. Copy Property " + oldPropertyCode + " to Property " + newPropertyCode + " on " + typeCode); @@ -51,14 +65,14 @@ public abstract class EntityPropertyCopy<ENTITY extends IPermIdHolder & IPropert if (entity.getProperty(oldPropertyCode) != null) { if(!entity.getProperty(oldPropertyCode).equals(entity.getProperty(newPropertyCode))) { updateEntityProperty(sessionToken, v3, entity); - System.out.println("[PREPARING] " + entity.getPermId() + "\t" + entity.getProperty(oldPropertyCode) + "\t" + total + "/" + entities.size()); + System.out.println("[PREPARING COPY] " + entity.getPermId() + "\t" + entity.getProperty(oldPropertyCode) + "\t" + total + "/" + entities.size()); } else { - System.out.println("[SKIP] " + entity.getPermId() + "\t" + entity.getProperty(oldPropertyCode) + "\t" + total + "/" + entities.size()); + System.out.println("[SKIP COPY] " + entity.getPermId() + "\t" + entity.getProperty(oldPropertyCode) + "\t" + total + "/" + entities.size()); } } total++; } - System.out.println("[DONE] " + total + "/" + entities.size()); + System.out.println("[DONE COPY] " + total + "/" + entities.size()); } } diff --git a/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyDelete.java b/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyDelete.java new file mode 100644 index 0000000000000000000000000000000000000000..c876c7d6b37b7041a0614027770df5b888b0b3b3 --- /dev/null +++ b/microscopy-migration-tool/src/ethz/ch/property/EntityPropertyDelete.java @@ -0,0 +1,16 @@ +package ethz.ch.property; + +import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; + +public abstract class EntityPropertyDelete { + + protected final String typeCode; + protected final String propertyCode; + + public EntityPropertyDelete(String typeCode, String propertyCode) { + this.typeCode = typeCode; + this.propertyCode = propertyCode; + } + + public abstract void deleteOldPropertyType(String sessionToken, IApplicationServerApi v3); +} diff --git a/microscopy-migration-tool/src/ethz/ch/property/PropertyType2SampleType.java b/microscopy-migration-tool/src/ethz/ch/property/PropertyType2SampleType.java index 935ffbdd687bbfe23f4c70615b1d31e8c4edcd13..bed6b62795c30f76013166a06d72b7a328aecb53 100644 --- a/microscopy-migration-tool/src/ethz/ch/property/PropertyType2SampleType.java +++ b/microscopy-migration-tool/src/ethz/ch/property/PropertyType2SampleType.java @@ -1,5 +1,7 @@ package ethz.ch.property; +import ethz.ch.sample.SamplePropertyDelete; + public class PropertyType2SampleType { private String oldSampleTypeCode; @@ -35,5 +37,9 @@ public class PropertyType2SampleType { return newPropertyCode; } + + public EntityPropertyDelete getEntityPropertyDelete() { + return new SamplePropertyDelete(oldSampleTypeCode, oldPropertyCode); + } } \ No newline at end of file diff --git a/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyCopy.java b/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyCopy.java index 76dbc7b2f7c3648f92ab8740232224af78ca498e..d820b3e2591a74f8da60eeaa4dacc74a9f6c98d7 100644 --- a/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyCopy.java +++ b/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyCopy.java @@ -6,6 +6,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.Sample; import ethz.ch.MasterdataHelper; import ethz.ch.MetadataHelper; import ethz.ch.property.EntityPropertyCopy; +import ethz.ch.property.EntityPropertyDelete; import java.util.List; @@ -22,7 +23,7 @@ public class SamplePropertyCopy extends EntityPropertyCopy<Sample> { @Override public void updatePropertyAssignmentsHolder(String sessionToken, IApplicationServerApi v3) { - MasterdataHelper.updateSampleType(sessionToken, v3, typeCode, 1, newPropertyCode); + MasterdataHelper.updateSampleType(sessionToken, v3, typeCode, MasterdataHelper.PropertyTypeUpdateAction.ADD,1, newPropertyCode); } @Override @@ -34,4 +35,9 @@ public class SamplePropertyCopy extends EntityPropertyCopy<Sample> { public void updateEntityProperty(String sessionToken, IApplicationServerApi v3, Sample entity) { MetadataHelper.updateSampleProperty(sessionToken, v3, entity.getPermId().getPermId(), newPropertyCode, entity.getProperty(oldPropertyCode)); } + + @Override + public EntityPropertyDelete getEntityPropertyDelete() { + return new SamplePropertyDelete(typeCode, oldPropertyCode); + } } diff --git a/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyDelete.java b/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyDelete.java new file mode 100644 index 0000000000000000000000000000000000000000..2884399846bea8791b32410b3cdb12bc19f429ad --- /dev/null +++ b/microscopy-migration-tool/src/ethz/ch/sample/SamplePropertyDelete.java @@ -0,0 +1,31 @@ +package ethz.ch.sample; + +import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.PropertyAssignment; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.SampleType; +import ethz.ch.MasterdataHelper; +import ethz.ch.property.EntityPropertyDelete; + +public class SamplePropertyDelete extends EntityPropertyDelete { + + public SamplePropertyDelete(String typeCode, String propertyCode) { + super(typeCode, propertyCode); + } + + @Override + public void deleteOldPropertyType(String sessionToken, IApplicationServerApi v3) { + SampleType type = MasterdataHelper.getSampleType(sessionToken, v3, typeCode); + boolean found = false; + for(PropertyAssignment propertyAssignment:type.getPropertyAssignments()) { + found = propertyAssignment.getPropertyType().getCode().equals(propertyCode); + if (found) { + break; + } + } + if (found) { + MasterdataHelper.updateSampleType(sessionToken, v3, typeCode, MasterdataHelper.PropertyTypeUpdateAction.REMOVE, 1, propertyCode); + MasterdataHelper.deletePropertyType(sessionToken, v3, propertyCode); + System.out.println("[PROPERTY DELETE] " + "\t" + propertyCode); + } + } +}