Implementing service
This commit is contained in:
parent
3e0778e3f7
commit
be5ec42502
|
@ -1,15 +1,12 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Fishery extends Record {
|
||||
|
||||
public Fishery() {
|
||||
TextNode textNode = new TextNode("Fishery");
|
||||
addProperty(SOURCE_KEY, textNode);
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Fishery";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.InternalServerErrorException;
|
||||
|
@ -11,20 +8,19 @@ import javax.ws.rs.core.UriInfo;
|
|||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.grsf.publisher.record.property.Property;
|
||||
import org.gcube.grsf.publisher.freemarker.FreeMarker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import freemarker.template.Template;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Record {
|
||||
public abstract class Record {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public static final String DOMAIN_KEY = "Domain";
|
||||
public static final String SOURCE_KEY = "Source";
|
||||
|
||||
protected UriInfo uriInfo;
|
||||
|
||||
protected String id;
|
||||
|
@ -32,22 +28,18 @@ public class Record {
|
|||
protected ObjectMapper objectMapper;
|
||||
protected JsonNode jsonNode;
|
||||
|
||||
protected Map<String, JsonNode> properties;
|
||||
protected Set<String> groups;
|
||||
protected Set<String> tags;
|
||||
protected Set<String> resources;
|
||||
|
||||
public Record() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
this.properties = new HashMap<>();
|
||||
this.groups = new HashSet<>();
|
||||
this.tags = new HashSet<>();
|
||||
this.resources = new HashSet<>();
|
||||
}
|
||||
|
||||
protected void addProperty(String key, JsonNode value) {
|
||||
this.properties.put(key, value);
|
||||
}
|
||||
public abstract String getType();
|
||||
|
||||
protected void addGroup(String group) {
|
||||
this.groups.add(group);
|
||||
|
@ -69,23 +61,8 @@ public class Record {
|
|||
this.uriInfo = uriInfo;
|
||||
}
|
||||
|
||||
public void elaborate() {
|
||||
Iterator<String> iterator = jsonNode.fieldNames();
|
||||
while(iterator.hasNext()) {
|
||||
String originalKey = iterator.next();
|
||||
JsonNode originalValue = jsonNode.get(originalKey);
|
||||
Property property = new Property(originalKey, originalValue);
|
||||
property.elaborate();
|
||||
|
||||
String key = property.getKey();
|
||||
JsonNode value = property.getValue();
|
||||
this.properties.put(key, value);
|
||||
|
||||
this.groups.addAll(property.getGroups());
|
||||
this.tags.addAll(property.getTags());
|
||||
this.resources.addAll(property.getResources());
|
||||
|
||||
}
|
||||
public void elaborate() throws Exception {
|
||||
trasform();
|
||||
|
||||
}
|
||||
|
||||
|
@ -93,37 +70,43 @@ public class Record {
|
|||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void trasform() throws Exception {
|
||||
FreeMarker freeMarker = new FreeMarker();
|
||||
Template template = freeMarker.getTemplate(getType() + ".ftl");
|
||||
|
||||
}
|
||||
|
||||
public String create(String json) {
|
||||
try {
|
||||
this.jsonNode = objectMapper.readTree(json);
|
||||
elaborate();
|
||||
// TODO
|
||||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
elaborate();
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public String update(String json) {
|
||||
try {
|
||||
this.jsonNode = objectMapper.readTree(json);
|
||||
elaborate();
|
||||
// TODO
|
||||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
elaborate();
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
public String patch(String json) {
|
||||
try {
|
||||
this.jsonNode = objectMapper.readTree(json);
|
||||
elaborate();
|
||||
// TODO
|
||||
} catch (Exception e) {
|
||||
throw new InternalServerErrorException(e);
|
||||
}
|
||||
elaborate();
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -136,8 +119,6 @@ public class Record {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int count() {
|
||||
// TODO
|
||||
return 0;
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class Stock extends Record {
|
||||
|
||||
public Stock () {
|
||||
TextNode textNode = new TextNode("Stock");
|
||||
addProperty(SOURCE_KEY, textNode);
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Stock";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
package org.gcube.grsf.publisher.record;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.com.fasterxml.jackson.databind.node.TextNode;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class TraceabilityUnit extends Record {
|
||||
|
||||
public TraceabilityUnit(JsonNode jsonNode) {
|
||||
TextNode textNode = new TextNode("Traceability Unit");
|
||||
addProperty(SOURCE_KEY, textNode);
|
||||
@Override
|
||||
public String getType() {
|
||||
return "TraceabilityUnit";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
|||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path(FisheryRESTAPIs.COLLECTION_PATH + "/")
|
||||
@Path(FisheryRESTAPIs.COLLECTION_PATH + "/" )
|
||||
public class FisheryRESTAPIs extends BaseRESTAPIs<Fishery> {
|
||||
|
||||
@PathParam("source")
|
||||
|
|
|
@ -77,7 +77,13 @@ public class FreeMarkerTest {
|
|||
|
||||
for(File jsonFile : source.listFiles(filenameFilter)) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Map map = mapper.readValue(jsonFile, Map.class);
|
||||
@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);
|
||||
|
||||
|
@ -85,11 +91,6 @@ public class FreeMarkerTest {
|
|||
|
||||
logger.trace("Elaborating {} {} from file {}", sourceString, type, jsonFile.getName());
|
||||
|
||||
/**
|
||||
* We can also use this in template
|
||||
* <#assign uri_resolver_base_url="https://data.d4science.org/ctlg/GRSF_Admin">
|
||||
* <#assign include_sensitive=true>
|
||||
*/
|
||||
File out = new File(outputSourceDir, jsonFile.getName());
|
||||
out.delete();
|
||||
|
||||
|
|
Loading…
Reference in New Issue