resource-registry/src/main/java/org/gcube/informationsystem/resourceregistry/er/entity/FacetManagement.java

60 lines
1.8 KiB
Java

/**
*
*/
package org.gcube.informationsystem.resourceregistry.er.entity;
import org.codehaus.jettison.json.JSONObject;
import org.gcube.informationsystem.model.entity.Facet;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.er.ERManagement;
import org.gcube.informationsystem.resourceregistry.utils.Utility;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class FacetManagement extends EntityManagement<Facet> {
public FacetManagement() {
super(Facet.class);
}
public FacetManagement(OrientGraph orientGraph) {
super(Facet.class, orientGraph);
}
@Override
public String serialize() throws ResourceRegistryException {
return Utility.toJsonString((OrientVertex) vertex, true);
}
@Override
public JSONObject serializeAsJson() throws ResourceRegistryException {
return Utility.toJsonObject((OrientVertex) vertex, true);
}
public Vertex reallyCreate() throws FacetAlreadyPresentException, ResourceRegistryException {
return createVertex();
}
@Override
public Vertex reallyUpdate() throws ResourceRegistryException {
Vertex facet = getVertex();
facet = (Vertex) ERManagement.updateProperties(facet, jsonNode, ignoreKeys, ignoreStartWithKeys);
((OrientVertex) facet).save();
return facet;
}
public boolean reallyDelete() throws FacetNotFoundException, ResourceRegistryException {
getVertex().remove();
return true;
}
}