diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/CommonServiceUtils.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/CommonServiceUtils.java index a03fc0b..f3ff476 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/CommonServiceUtils.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/utils/CommonServiceUtils.java @@ -412,22 +412,22 @@ public class CommonServiceUtils { if(refersTo == null || refersTo.isEmpty()) throw new Exception("refers_to is empty for a GRSF record"); - List sourcesList = new ArrayList(); + Set sourcesList = new HashSet(); String databaseSource = ""; // we have the id within the catalog of this record. This means that we can retrieve the record and its system:type for (RefersToBean refersToBean : refersTo) { - String sourceSysType = getSystemTypeValue(refersToBean.getId(), apiKey, context); - resources.add(new ResourceBean(refersToBean.getUrl(), sourceSysType , "", null, username, null, null)); - sourcesList.add(sourceSysType.toLowerCase()); - databaseSource += sourceSysType + " "; + String sourceOrganization = getRecordOrganization(refersToBean.getId(), apiKey, context); + resources.add(new ResourceBean(refersToBean.getUrl(), sourceOrganization , "", null, username, null, null)); + sourcesList.add(sourceOrganization.toLowerCase()); + databaseSource += sourceOrganization + " "; } // create the Database Source information customFields.put(Constants.GRSF_DATABASE_SOURCE, Arrays.asList(databaseSource.trim())); // append to groups: we need to add this record to the correspondent group of the sources - addRecordToGroupSources(groups, sourcesList, productType, sourceInPath); + addRecordToGroupSources(groups, new ArrayList(sourcesList), productType, sourceInPath); // validate CommonServiceUtils.validateAggregatedRecord(record); @@ -489,6 +489,18 @@ public class CommonServiceUtils { else return systemTypeValue; + } + + public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception{ + + DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context); + CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey); + if(dataset == null) + throw new Exception("Unable to find record with id or name " + itemIdOrName); + else + return dataset.getOrganization().getTitle(); + + } /**