diff --git a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/exporter/ExportExecutor.java b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/exporter/ExportExecutor.java index 9c4e50f2c486275b8047874edc29dacab23a7138..e9ab16616530ab36b80796e3ef6261741aa831d5 100644 --- a/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/exporter/ExportExecutor.java +++ b/server-application-server/source/java/ch/ethz/sis/openbis/generic/server/asapi/v3/executor/exporter/ExportExecutor.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -40,6 +41,7 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.exporter.options.ExportOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.importer.ImportOperation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.importer.options.ImportOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.IPropertyTypeId; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.property.id.PropertyTypePermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.SampleType; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions.SampleTypeFetchOptions; import ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.search.SampleTypeSearchCriteria; @@ -59,6 +61,10 @@ import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider; public class ExportExecutor implements IExportExecutor { + private static final String TYPE = "type"; + + private static final String ID = "id"; + @Override public void doExport(final IOperationContext context, final ExportOperation operation) { @@ -97,24 +103,32 @@ public class ExportExecutor implements IExportExecutor final Collection<Attribute> attributes = EnumSet.copyOf(selectedFields.getAttributes()); if (attributes.size() > 0) { - final Map<String, List<Map<String, String>>> selectedAttributes = + final Map<String, List<Map<String, String>>> selectedAttributeMap = attributes.stream().collect(Collectors.toMap(Attribute::name, this::convertAttributeToMap)); - exportFields.put("TYPE", selectedAttributes); + exportFields.put("TYPE", selectedAttributeMap); } - + final Set<PropertyTypePermId> selectedPropertyTypePermIds = new HashSet<>(selectedFields.getProperties()); final Collection<IPropertyTypeId> properties = new ArrayList<>(selectedFields.getProperties()); - // Do similar for experiments and datasets - final SampleTypeSearchCriteria searchCriteria = new SampleTypeSearchCriteria(); - searchCriteria.withPropertyAssignments().withPropertyType().withIds().thatIn(properties); - final SearchResult<SampleType> sampleTypeSearchResult = - applicationServerApi.searchSampleTypes(sessionToken, searchCriteria, new SampleTypeFetchOptions()); - final List<SampleType> sampleTypes = sampleTypeSearchResult.getObjects(); - selectedFields.getProperties().get(0). - // TODO: how to map PropertyTypePermId to entity kind? - properties.stream().collect(Collectors.toMap(propertyTypePermId -> propertyTypePermId.)) + // TODO: Do something similar for experiments and datasets + + final SampleTypeSearchCriteria typeSearchCriteria = new SampleTypeSearchCriteria(); + typeSearchCriteria.withPropertyAssignments().withPropertyType().withIds().thatIn(properties); + final SearchResult<SampleType> entityTypeSearchResult = + applicationServerApi.searchSampleTypes(sessionToken, typeSearchCriteria, new SampleTypeFetchOptions()); + + final ExportableKind exportableKind = ExportableKind.SAMPLE; + + final List<SampleType> sampleTypes = entityTypeSearchResult.getObjects(); + final Map<String, List<Map<String, String>>> sampleSelectedPropertyMap = + sampleTypes.stream().collect(Collectors.toMap(sampleType -> sampleType.getPermId().getPermId(), + sampleType -> sampleType.getPropertyAssignments().stream().filter(propertyAssignment -> + selectedPropertyTypePermIds.contains(propertyAssignment.getPropertyType().getPermId())) + .map(propertyAssignment -> Map.of(TYPE, FieldType.PROPERTY.name(), ID, + propertyAssignment.getPropertyType().getCode())).collect(Collectors.toList()))); + exportFields.put(exportableKind.name(), sampleSelectedPropertyMap); } else { exportFields = null; @@ -134,38 +148,38 @@ public class ExportExecutor implements IExportExecutor private List<Map<String, String>> convertAttributeToMap(final Attribute attribute) { final List<Map<String, String>> result = new ArrayList<>(); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.CODE.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.DESCRIPTION.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.CODE.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.DESCRIPTION.getName())); switch (attribute) { case SPACE: { - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), "id", + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.REGISTRATOR.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), "id", + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.REGISTRATION_DATE.getName())); break; } case SAMPLE_TYPE: { - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), "id", + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.AUTO_GENERATE_CODES.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.VALIDATION_SCRIPT.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.GENERATED_CODE_PREFIX.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.UNIQUE_SUBCODES.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.MODIFICATION_DATE.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.VALIDATION_SCRIPT.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.GENERATED_CODE_PREFIX.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.UNIQUE_SUBCODES.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.MODIFICATION_DATE.getName())); break; } case EXPERIMENT_TYPE: { - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.VALIDATION_SCRIPT.getName())); - result.add(Map.of("type", FieldType.ATTRIBUTE.name(), - "id", ch.ethz.sis.openbis.generic.server.xls.export.Attribute.MODIFICATION_DATE.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.VALIDATION_SCRIPT.getName())); + result.add(Map.of(TYPE, FieldType.ATTRIBUTE.name(), + ID, ch.ethz.sis.openbis.generic.server.xls.export.Attribute.MODIFICATION_DATE.getName())); break; } } diff --git a/ui-admin/src/core-plugins/admin/1/as/services/xls-export/xls-export.py b/ui-admin/src/core-plugins/admin/1/as/services/xls-export/xls-export.py index 499602fba1e5481402cb245d7636a3f4e20d8716..f9689079d48e18d0e8266a9f8f2c40affe0e7bb1 100644 --- a/ui-admin/src/core-plugins/admin/1/as/services/xls-export/xls-export.py +++ b/ui-admin/src/core-plugins/admin/1/as/services/xls-export/xls-export.py @@ -39,7 +39,7 @@ def export(context, parameters): ... }, "SAMPLE": { - "<typePermID>": [ + "<sampleTypePermID>": [ {"type": "PROPERTY", "id": "<property code>"}, {"type": "ATTRIBUTE", "id": "<attribute name>"}, ... @@ -48,7 +48,7 @@ def export(context, parameters): for the sample type }, "EXPERIMENT": { - "<typePermID>": [ + "<experimentTypePermID>": [ {"type": "PROPERTY", "id": "<property code>"}, {"type": "ATTRIBUTE", "id": "<attribute name>"}, ... @@ -57,7 +57,7 @@ def export(context, parameters): for the experiment type }, "DATASET": { - "<typePermID>": [ + "<dataSetTypePermID>": [ {"type": "PROPERTY", "id": "<property code>"}, {"type": "ATTRIBUTE", "id": "<attribute name>"} , ...