Fixing service
This commit is contained in:
parent
9913c5e99c
commit
8f32350b82
|
@ -13,10 +13,12 @@ import org.gcube.grsf.publisher.utils.OrganizationUtils;
|
|||
public class GRSFCatalogueConfiguration extends ServiceCatalogueConfiguration {
|
||||
|
||||
protected Set<String> grsfSupportedOrganizations;
|
||||
|
||||
protected boolean includeSensitive;
|
||||
|
||||
public GRSFCatalogueConfiguration() {
|
||||
Map<String,String> organizationMap = OrganizationUtils.getInstance().getOrganizations();
|
||||
this.grsfSupportedOrganizations = organizationMap.keySet();
|
||||
this.includeSensitive = true;
|
||||
}
|
||||
|
||||
@JsonGetter(value = SOCIAL_POST_ENABLED_KEY)
|
||||
|
@ -56,4 +58,12 @@ public class GRSFCatalogueConfiguration extends ServiceCatalogueConfiguration {
|
|||
return grsfSupportedOrganizations;
|
||||
}
|
||||
|
||||
public boolean isIncludeSensitive() {
|
||||
return includeSensitive;
|
||||
}
|
||||
|
||||
public void setIncludeSensitive(boolean includeSensitive) {
|
||||
this.includeSensitive = includeSensitive;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import javax.ws.rs.InternalServerErrorException;
|
|||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.gcube.com.fasterxml.jackson.core.type.TypeReference;
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -34,11 +33,14 @@ import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.gcat.api.GCatConstants;
|
||||
import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
|
||||
import org.gcube.gcat.persistence.ckan.CKAN;
|
||||
import org.gcube.gcat.persistence.ckan.CKANPackage;
|
||||
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
||||
import org.gcube.gcat.persistence.ckan.CKANResource;
|
||||
import org.gcube.gcat.utils.Constants;
|
||||
import org.gcube.gcat.utils.URIResolver;
|
||||
import org.gcube.grsf.publisher.GRSFInitializator;
|
||||
import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfiguration;
|
||||
import org.gcube.grsf.publisher.freemarker.FreeMarker;
|
||||
import org.gcube.grsf.publisher.utils.TypeUtils;
|
||||
import org.gcube.storagehub.MetadataMatcher;
|
||||
|
@ -110,7 +112,6 @@ public abstract class Record extends CKANPackage {
|
|||
Template tsTemplate = freeMarker.getTemplate("timeseries.ftl");
|
||||
Template template = freeMarker.getTemplate(getType() + ".ftl");
|
||||
Map<String, Object> map = getMapFromSourceJson(node);
|
||||
grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
|
||||
File transformedJson = getTransformedJsonFile(template,map);
|
||||
jsonNode = mapper.readTree(transformedJson);
|
||||
jsonNode = elaborateTimeSeries(tsTemplate,map);
|
||||
|
@ -215,13 +216,16 @@ public abstract class Record extends CKANPackage {
|
|||
return fileContainer;
|
||||
}
|
||||
|
||||
protected Map<String, Object> getMapFromSourceJson(JsonNode jsonNode) throws JsonProcessingException {
|
||||
protected Map<String, Object> getMapFromSourceJson(JsonNode jsonNode) throws Exception {
|
||||
Map<String, Object> map = objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>(){});
|
||||
grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
|
||||
|
||||
// TODO Get from IS
|
||||
map.put("uri_resolver_base_url", "https://data.d4science.org/ctlg/GRSF_Admin");
|
||||
// TODO get from Configuration
|
||||
map.put("include_sensitive", true);
|
||||
URIResolver uriResolver = URIResolver.getInstance();
|
||||
String recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
|
||||
map.put("record_url", recordURL);
|
||||
|
||||
GRSFCatalogueConfiguration grsfCC = (GRSFCatalogueConfiguration) CatalogueConfigurationFactory.getInstance();
|
||||
map.put("include_sensitive", grsfCC.isIncludeSensitive());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
@ -323,9 +327,6 @@ public abstract class Record extends CKANPackage {
|
|||
|
||||
parseResult();
|
||||
|
||||
String userFullName = CKANUserCache.getCurrrentCKANUser().getNameSurname();
|
||||
sendSocialPost(userFullName);
|
||||
|
||||
return getAsCleanedString(result);
|
||||
|
||||
} catch(WebApplicationException e) {
|
||||
|
@ -360,13 +361,31 @@ public abstract class Record extends CKANPackage {
|
|||
@Override
|
||||
public String update(String json) {
|
||||
try {
|
||||
JsonNode jsonNode = objectMapper.readTree(json);
|
||||
elaborate(jsonNode);
|
||||
// TODO
|
||||
this.updateOperation = true;
|
||||
|
||||
this.result = null;
|
||||
readItem();
|
||||
|
||||
ArrayNode originalResourcesarrayNode = (ArrayNode) result.get(RESOURCES_KEY);
|
||||
for(JsonNode resourceNode : originalResourcesarrayNode) {
|
||||
CKANResource ckanResource = new CKANResource(itemID);
|
||||
ckanResource.setPreviousRepresentation(resourceNode);
|
||||
ckanResource.deleteFile();
|
||||
}
|
||||
|
||||
JsonNode jNode = objectMapper.readTree(json);
|
||||
elaborate(jNode);
|
||||
|
||||
String jsonString = objectMapper.writeValueAsString(jsonNode);
|
||||
sendPostRequest(ITEM_UPDATE, jsonString);
|
||||
|
||||
parseResult();
|
||||
|
||||
return getAsCleanedString(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
<#assign group_list = [] >
|
||||
<#assign tag_list = [] >
|
||||
|
||||
<#assign record_url="${uri_resolver_base_url}/${grsf_uuid}" />
|
||||
|
||||
<#assign description = "Short Name: ${short_name}\n" >
|
||||
<#if grsf_semantic_identifier??>
|
||||
<#assign description += "GRSF Semantic Identifier: ${grsf_semantic_identifier}\n" >
|
||||
|
|
|
@ -14,13 +14,18 @@ import java.util.regex.Pattern;
|
|||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import org.gcube.gcat.configuration.CatalogueConfigurationFactory;
|
||||
import org.gcube.gcat.utils.URIResolver;
|
||||
import org.gcube.grsf.publisher.ContextTest;
|
||||
import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfiguration;
|
||||
import org.gcube.grsf.publisher.record.Record;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import freemarker.template.Template;
|
||||
|
||||
public class FreeMarkerTest {
|
||||
public class FreeMarkerTest extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(FreeMarkerTest.class);
|
||||
|
||||
|
@ -40,6 +45,9 @@ public class FreeMarkerTest {
|
|||
public void testIt() throws Exception {
|
||||
FreeMarker freeMarker = new FreeMarker();
|
||||
|
||||
GRSFCatalogueConfiguration grsfCC = (GRSFCatalogueConfiguration) CatalogueConfigurationFactory.getInstance();
|
||||
URIResolver uriResolver = URIResolver.getInstance();
|
||||
|
||||
Template tsTemplate = freeMarker.getTemplate("timeseries.ftl");
|
||||
|
||||
String[] types = new String[] {"Stock", "Fishery", "TraceabilityUnit"};
|
||||
|
@ -101,13 +109,11 @@ public class FreeMarkerTest {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> map = mapper.readValue(jsonFile, Map.class);
|
||||
/**
|
||||
* We could also use this in template
|
||||
* <#assign uri_resolver_base_url="https://data.d4science.org/ctlg/GRSF_Admin">
|
||||
* <#assign include_sensitive=true>
|
||||
*/
|
||||
map.put("uri_resolver_base_url", "https://data.d4science.org/ctlg/GRSF_Admin");
|
||||
map.put("include_sensitive", true);
|
||||
String grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
|
||||
|
||||
String recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
|
||||
map.put("record_url", recordURL);
|
||||
map.put("include_sensitive", grsfCC.isIncludeSensitive());
|
||||
|
||||
map.put("source", sourceString);
|
||||
|
||||
|
|
Loading…
Reference in New Issue