diff --git a/java/cukes/src/test/java/io/opensaber/registry/test/RegistryIntegrationSteps.java b/java/cukes/src/test/java/io/opensaber/registry/test/RegistryIntegrationSteps.java index 7444330a2..c4a93d2eb 100644 --- a/java/cukes/src/test/java/io/opensaber/registry/test/RegistryIntegrationSteps.java +++ b/java/cukes/src/test/java/io/opensaber/registry/test/RegistryIntegrationSteps.java @@ -46,7 +46,7 @@ public class RegistryIntegrationSteps extends RegistryTestBase{ private static final String VALID_NEWJSONLD= "teacher.jsonld"; private static final String INVALID_LABEL_JSONLD = "invalid-label.jsonld"; private static final String INVALID_NEWJSONLD= "invalid-teacher.jsonld"; - private static final String ADD_ENTITY = "create"; + private static final String ADD_ENTITY = "add"; private static final String READ_ENTITY = "read"; private static final String AUTH_HEADER_NAME = "x-authenticated-user-token"; @@ -180,7 +180,6 @@ private void setInvalidAuthHeader(){ public void issueRecordInRegistry(String qualifier) throws JsonParseException, JsonMappingException, IOException{ jsonldData(); updateId = id; - System.out.println("Id getting inserted into db:"+id); setValidAuthToken(); addEntity(); checkSuccessfulResponse(); @@ -213,7 +212,7 @@ public void retrieving_the_record_from_the_registry(){ private ResponseEntity callRegistryReadAPI() { HttpEntity entity = new HttpEntity<>(headers); - ResponseEntity response = restTemplate.exchange(baseUrl+READ_ENTITY+"/"+id, HttpMethod.GET,entity,Response.class); + ResponseEntity response = restTemplate.exchange(baseUrl+"/"+id, HttpMethod.GET,entity,Response.class); return response; } diff --git a/java/cukes/src/test/java/io/opensaber/registry/test/RegistryTestBase.java b/java/cukes/src/test/java/io/opensaber/registry/test/RegistryTestBase.java index bc326c28b..ce2c1328d 100644 --- a/java/cukes/src/test/java/io/opensaber/registry/test/RegistryTestBase.java +++ b/java/cukes/src/test/java/io/opensaber/registry/test/RegistryTestBase.java @@ -28,7 +28,6 @@ public class RegistryTestBase { private static final String REPLACING_SUBJECT_LABEL = "<@id>"; private static final String EMPTY_STRING = ""; private static final String CONTEXT_CONSTANT = "teacher:"; - private static final String CONTEXT_URL = "http://example.com/voc/teacher/1.0.0/"; protected RestTemplate restTemplate; public void setJsonld(String filename) { @@ -85,7 +84,7 @@ public void setJsonldWithNewRootLabel(String id) { public static String extractIdWithoutContext(String label) { String extractedId = label; - Pattern pattern = Pattern.compile("^" + Pattern.quote(CONTEXT_URL) + "(.*?)$"); + Pattern pattern = Pattern.compile("^" + Pattern.quote(Constants.INTEGRATION_TEST_BASE_URL) + "(.*?)$"); Matcher matcher = pattern.matcher(label); if(matcher.find()) { extractedId = matcher.group(1); @@ -115,7 +114,7 @@ public ResponseEntity fetchEntity(String url, HttpHeaders headers) { return response; } - /*public ResponseEntity addEntity(String jsonldData, String url, HttpHeaders headers) { + public ResponseEntity addEntity(String jsonldData, String url, HttpHeaders headers) { HttpEntity entity = new HttpEntity<>(jsonldData, headers); ResponseEntity response = restTemplate.postForEntity(url, entity, Response.class); return response; @@ -123,8 +122,8 @@ public ResponseEntity fetchEntity(String url, HttpHeaders headers) { public ResponseEntity update(String jsonldData, String url, HttpHeaders headers) { HttpEntity entity = new HttpEntity<>(jsonldData, headers); - Response response = restTemplate.patchForObject(url, entity, Response.class); - return new ResponseEntity(response, HttpStatus.OK); + ResponseEntity response = restTemplate.postForEntity(url, entity, Response.class); + return response; } public ResponseEntity readEntity(String url, HttpHeaders headers, String id) { @@ -133,6 +132,6 @@ public ResponseEntity readEntity(String url, HttpHeaders headers, Stri queryParams.put("id", id); ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, entity, Response.class,queryParams); return response; - }*/ + } } diff --git a/java/cukes/src/test/java/io/opensaber/registry/test/UpdateIntegrationTestSteps.java b/java/cukes/src/test/java/io/opensaber/registry/test/UpdateIntegrationTestSteps.java index 290f07fd5..82667b220 100644 --- a/java/cukes/src/test/java/io/opensaber/registry/test/UpdateIntegrationTestSteps.java +++ b/java/cukes/src/test/java/io/opensaber/registry/test/UpdateIntegrationTestSteps.java @@ -47,7 +47,7 @@ public class UpdateIntegrationTestSteps extends RegistryTestBase implements En { private static final String VALID_UPDATE_JSONLD_FILE = "update_teacher.jsonld"; private static final String UPDATE_JSONLD__AUDIT_FILE = "update_teacher_audit.jsonld"; private static final String INVALID_UPDATE_JSONLD = "invalid-teacher.jsonld"; - private static final String CREATE_REST_ENDPOINT = "create"; + private static final String CREATE_REST_ENDPOINT = "add"; private static final String UPDATE_REST_ENDPOINT = "update"; private static final String READ_REST_ENDPOINT = "read"; private static final String CONTEXT_CONSTANT = "sample:"; @@ -87,8 +87,9 @@ private void initializeCommonSteps() { When("^updating the record in the registry$", () -> { StringBuilder url = new StringBuilder(); - url.append(baseUrl).append(UPDATE_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); - response = updateEntity(jsonld, url.toString(), headers); + //url.append(baseUrl).append(UPDATE_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); + url.append(baseUrl).append(UPDATE_REST_ENDPOINT); + response = update(jsonld, url.toString(), headers); }); Then("^updating the record should be unsuccessful$", () -> checkUnsuccessfulResponse()); @@ -99,14 +100,16 @@ private void initializeCommonSteps() { Given("^valid data for updating a record$", () -> { StringBuilder url = new StringBuilder(); - url.append(baseUrl).append(READ_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); + //url.append(baseUrl).append(READ_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); + url.append(id); response = fetchEntity(url.toString(), headers); jsonld = updateInputJsonldRootNodeId(response, "update_teacher.jsonld"); }); Given("^input for updating single record$", () -> { StringBuilder url = new StringBuilder(); - url.append(baseUrl).append(READ_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); + //url.append(baseUrl).append(READ_REST_ENDPOINT).append("/").append(extractIdWithoutContext(id)); + url.append(id); response = fetchEntity(url.toString(), headers); jsonld = updateInputJsonldRootNodeId(response, "update_teacher_audit.jsonld"); }); @@ -193,7 +196,7 @@ private void verifyUnsuccessfulMessage(String message) { private void verifyValidationErrorMessage(String message) { Map result = response.getBody().getResult(); Map validationErrorData = (Map) result.get("data"); - String validationError = validationErrorData.get("http://example.com/voc/teacher/1.0.0/serialNum"); + String validationError = validationErrorData.get(Constants.INTEGRATION_TEST_BASE_URL+"serialNum"); assertEquals(message, validationError); } diff --git a/java/cukes/src/test/resources/create_teacher.jsonld b/java/cukes/src/test/resources/create_teacher.jsonld index a3b22e3ff..7dc4dda30 100644 --- a/java/cukes/src/test/resources/create_teacher.jsonld +++ b/java/cukes/src/test/resources/create_teacher.jsonld @@ -11,9 +11,9 @@ "@context":{ "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs":"http://www.w3.org/2000/01/rdf-schema#", - "teacher":"http://example.com/voc/teacher/1.0.0/", + "teacher":"http://localhost:8080/", "xsd":"http://www.w3.org/2001/XMLSchema#", - "@vocab":"http://example.com/voc/teacher/1.0.0/" + "@vocab":"http://localhost:8080/" }, "@type":"Teacher", "serialNum":12, diff --git a/java/cukes/src/test/resources/invalid-teacher.jsonld b/java/cukes/src/test/resources/invalid-teacher.jsonld index 478da3fca..b12ee3f16 100644 --- a/java/cukes/src/test/resources/invalid-teacher.jsonld +++ b/java/cukes/src/test/resources/invalid-teacher.jsonld @@ -11,9 +11,9 @@ "@context":{ "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs":"http://www.w3.org/2000/01/rdf-schema#", - "teacher":"http://example.com/voc/teacher/1.0.0/", + "teacher":"http://localhost:8080/", "xsd":"http://www.w3.org/2001/XMLSchema#", - "@vocab":"http://example.com/voc/teacher/1.0.0/" + "@vocab":"http://localhost:8080/" }, "@id":"<@id>", "@type":"Teacher", diff --git a/java/cukes/src/test/resources/school.jsonld b/java/cukes/src/test/resources/school.jsonld index dcc872166..7d83591bb 100644 --- a/java/cukes/src/test/resources/school.jsonld +++ b/java/cukes/src/test/resources/school.jsonld @@ -29,6 +29,6 @@ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "xsd": "http://www.w3.org/2001/XMLSchema#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "sample": "http://example.com/voc/teacher/1.0.0/" + "sample": "http://localhost:8080/" } } diff --git a/java/cukes/src/test/resources/teacher.jsonld b/java/cukes/src/test/resources/teacher.jsonld index 545100ef1..d533be87f 100644 --- a/java/cukes/src/test/resources/teacher.jsonld +++ b/java/cukes/src/test/resources/teacher.jsonld @@ -15,9 +15,9 @@ { "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "teacher": "http://example.com/voc/teacher/1.0.0/", + "teacher": "http://localhost:8080/", "xsd": "http://www.w3.org/2001/XMLSchema#", - "@vocab": "http://example.com/voc/teacher/1.0.0/" + "@vocab": "http://localhost:8080/" }, "@id": "<@id>", diff --git a/java/cukes/src/test/resources/update_teacher.jsonld b/java/cukes/src/test/resources/update_teacher.jsonld index 087e1a5e0..6bdfdaace 100644 --- a/java/cukes/src/test/resources/update_teacher.jsonld +++ b/java/cukes/src/test/resources/update_teacher.jsonld @@ -11,9 +11,9 @@ "@context":{ "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs":"http://www.w3.org/2000/01/rdf-schema#", - "teacher":"http://example.com/voc/teacher/1.0.0/", + "teacher":"http://localhost:8080/", "xsd":"http://www.w3.org/2001/XMLSchema#", - "@vocab":"http://example.com/voc/teacher/1.0.0/" + "@vocab":"http://localhost:8080/" }, "@type":"Teacher", "serialNum":12, diff --git a/java/cukes/src/test/resources/update_teacher_audit.jsonld b/java/cukes/src/test/resources/update_teacher_audit.jsonld index 3fa86ceda..ea15f0a98 100644 --- a/java/cukes/src/test/resources/update_teacher_audit.jsonld +++ b/java/cukes/src/test/resources/update_teacher_audit.jsonld @@ -11,9 +11,9 @@ "@context":{ "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs":"http://www.w3.org/2000/01/rdf-schema#", - "teacher":"http://example.com/voc/teacher/1.0.0/", + "teacher":"http://localhost:8080/", "xsd":"http://www.w3.org/2001/XMLSchema#", - "@vocab":"http://example.com/voc/teacher/1.0.0/" + "@vocab":"http://localhost:8080/" }, "@type":"Teacher", "serialNum":14 diff --git a/java/middleware-commons/src/main/java/io/opensaber/registry/middleware/util/Constants.java b/java/middleware-commons/src/main/java/io/opensaber/registry/middleware/util/Constants.java index 21dc62f6a..e040ee14d 100644 --- a/java/middleware-commons/src/main/java/io/opensaber/registry/middleware/util/Constants.java +++ b/java/middleware-commons/src/main/java/io/opensaber/registry/middleware/util/Constants.java @@ -16,7 +16,7 @@ public class Constants { public static final String SHAPE_TYPE = "validations.entity.shape.type"; public static final String FEATURE_TOGGLING = "feature.toggling"; public static final String RDF_VALIDATION_MAPPER_OBJECT = "rdfValidationMapper"; - public static final String REGISTRY_CONTEXT_BASE = "registry.context.base"; + public static final String REGISTRY_CONTEXT_BASE = "registry.base"; public static final String PRIVACY_PROPERTY = "privateProperties"; public static final String OPENSABER_CONTEXT_BASE = "http://example.com/voc/opensaber/1.0.0/"; @@ -31,14 +31,14 @@ public class Constants { public static final String DUPLICATE_RECORD_MESSAGE = "Cannot insert duplicate record"; public static final String FAILED_INSERTION_MESSAGE = "Failed to insert record"; - public static final String NO_ENTITY_AVAILABLE_MESSAGE = "No entity to create or update"; + public static final String NO_ENTITY_AVAILABLE_MESSAGE = "No entity available"; public static final String ENTITY_NOT_FOUND = "Entity does not exist"; public static final String TOKEN_EXTRACTION_ERROR = "Unable to extract auth token"; public static final String JSONLD_PARSE_ERROR = "Unable to parse JSON-LD"; public static final String RDF_VALIDATION_ERROR = "Unable to validate RDF"; public static final String RDF_VALIDATION_MAPPING_ERROR = "Unable to map validations"; public static final String CUSTOM_EXCEPTION_ERROR = "Something went wrong!! Please try again later"; - public static final String ADD_UPDATE_MULTIPLE_ENTITIES_MESSAGE = "Cannot add/update more than one entity"; + public static final String ADD_UPDATE_MULTIPLE_ENTITIES_MESSAGE = "Cannot add/update/view more than one entity"; public static final String OPENSABER_REGISTRY_API_NAME = "opensaber-registry-api"; public static final String SUNBIRD_ENCRYPTION_SERVICE_NAME = "sunbird.encryption.service"; diff --git a/java/registry/pom.xml b/java/registry/pom.xml index 019cf7886..faf0ef89a 100644 --- a/java/registry/pom.xml +++ b/java/registry/pom.xml @@ -216,6 +216,11 @@ schema-configuration 0.0.1-SNAPSHOT + + commons-validator + commons-validator + 1.6 + diff --git a/java/registry/src/main/java/io/opensaber/registry/config/GenericConfiguration.java b/java/registry/src/main/java/io/opensaber/registry/config/GenericConfiguration.java index f7db31296..b51cd53e8 100644 --- a/java/registry/src/main/java/io/opensaber/registry/config/GenericConfiguration.java +++ b/java/registry/src/main/java/io/opensaber/registry/config/GenericConfiguration.java @@ -154,22 +154,12 @@ public RDFValidationMapper rdfValidationMapper(){ public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new AuthorizationInterceptor(authorizationFilter(), gson())) .addPathPatterns("/**").excludePathPatterns("/health", "/error").order(1); - boolean featureToggling = Boolean.parseBoolean(environment.getProperty(Constants.FEATURE_TOGGLING)); - if(featureToggling){ - registry.addInterceptor(new RDFConversionInterceptor(rdfConverter(), gson())) - .addPathPatterns("/add", "/update").order(2); - registry.addInterceptor(new RDFValidationMappingInterceptor(rdfValidationMapper(), gson())) - .addPathPatterns("/add", "/update").order(3); - registry.addInterceptor(new RDFValidationInterceptor(rdfValidator(), gson())) - .addPathPatterns("/add", "/update").order(4); - } else { - registry.addInterceptor(new RDFConversionInterceptor(rdfConverter(), gson())) - .addPathPatterns("/create", "/update/{id}").order(2); - registry.addInterceptor(new RDFValidationMappingInterceptor(rdfValidationMapper(), gson())) - .addPathPatterns("/create", "/update/{id}").order(3); - registry.addInterceptor(new RDFValidationInterceptor(rdfValidator(), gson())) - .addPathPatterns("/create", "/update/{id}").order(4); - } + registry.addInterceptor(new RDFConversionInterceptor(rdfConverter(), gson())) + .addPathPatterns("/create", "/update/{id}","/add", "/update").order(2); + registry.addInterceptor(new RDFValidationMappingInterceptor(rdfValidationMapper(), gson())) + .addPathPatterns("/create", "/update/{id}","/add", "/update").order(3); + registry.addInterceptor(new RDFValidationInterceptor(rdfValidator(), gson())) + .addPathPatterns("/create", "/update/{id}", "/add", "/update").order(4); /*registry.addInterceptor(new JSONLDConversionInterceptor(jsonldConverter())) .addPathPatterns("/read/{id}").order(2);*/ } diff --git a/java/registry/src/main/java/io/opensaber/registry/controller/RegistryController.java b/java/registry/src/main/java/io/opensaber/registry/controller/RegistryController.java index 14397a75f..4adf99d92 100644 --- a/java/registry/src/main/java/io/opensaber/registry/controller/RegistryController.java +++ b/java/registry/src/main/java/io/opensaber/registry/controller/RegistryController.java @@ -1,18 +1,15 @@ package io.opensaber.registry.controller; import java.lang.reflect.Type; -import java.sql.Blob; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; -import javax.websocket.server.PathParam; import io.opensaber.pojos.HealthCheckResponse; import io.opensaber.registry.middleware.util.Constants; import io.opensaber.registry.util.JSONUtil; -import org.apache.jena.atlas.json.JSON; import org.apache.jena.rdf.model.Model; import org.json.JSONObject; import org.slf4j.Logger; @@ -21,7 +18,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.RequestMapping; @@ -30,18 +26,12 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import io.opensaber.pojos.Request; import io.opensaber.pojos.Response; import io.opensaber.pojos.ResponseParams; -import io.opensaber.pojos.ValidationResponse; -import io.opensaber.pojos.ValidationResponseSerializer; import io.opensaber.registry.exception.DuplicateRecordException; import io.opensaber.registry.exception.EntityCreationException; import io.opensaber.registry.exception.RecordNotFoundException; @@ -58,9 +48,6 @@ public class RegistryController { @Value("${registry.context.base}") private String registryContext; - @Value("${registry.system.base}") - private String registrySystemContext; - @RequestMapping(value = "/create", method = RequestMethod.POST) public ResponseEntity addEntity(@RequestAttribute Request requestModel) { Model rdf = (Model) requestModel.getRequestMap().get("rdf"); @@ -88,15 +75,15 @@ public ResponseEntity addEntity(@RequestAttribute Request requestModel @RequestMapping(value = "/add", method = RequestMethod.POST) public ResponseEntity addToExistingEntity(@RequestAttribute Request requestModel, - @RequestParam("id") String id, @RequestParam("prop") String property) { - + @RequestParam(value="id", required = false) String id, @RequestParam(value="prop", required = false) String property) { + Model rdf = (Model) requestModel.getRequestMap().get("rdf"); ResponseParams responseParams = new ResponseParams(); Response response = new Response(Response.API_ID.CREATE, "OK", responseParams); Map result = new HashMap<>(); try { - String label = registryService.addToExistingEntity(rdf, id, property); + String label = registryService.addEntity(rdf, id, property); result.put("entity", label); response.setResult(result); responseParams.setStatus(Response.Status.SUCCCESSFUL); @@ -140,6 +127,34 @@ public ResponseEntity getEntity(@PathVariable("id") String id) { return new ResponseEntity<>(response, HttpStatus.OK); } + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public ResponseEntity readEntity(@PathVariable("id") String id) { + id = registryContext + id; + ResponseParams responseParams = new ResponseParams(); + Response response = new Response(Response.API_ID.READ, "OK", responseParams); + + try { + org.eclipse.rdf4j.model.Model entityModel = registryService.getEntityById(id); + logger.debug("FETCHED: " + entityModel); + String jenaJSON = registryService.frameEntity(entityModel); + JSONObject jenaObj = new JSONObject(jenaJSON); + /*Map resultMap = new HashMap(); + resultMap.put(Constants.RESPONSE_ATTRIBUTE, entityModel);*/ + response.setResult(jenaObj.toMap()); + responseParams.setStatus(Response.Status.SUCCCESSFUL); + } catch (RecordNotFoundException e) { + response.setResult(null); + responseParams.setStatus(Response.Status.UNSUCCESSFUL); + responseParams.setErrmsg(e.getMessage()); + } catch (Exception e) { + response.setResult(null); + responseParams.setStatus(Response.Status.UNSUCCESSFUL); + responseParams.setErrmsg("Ding! You encountered an error!"); + logger.error("ERROR!", e); + } + return new ResponseEntity<>(response, HttpStatus.OK); + } + @ResponseBody @RequestMapping(value = "/update/{id}", method = RequestMethod.PATCH) public ResponseEntity updateEntity(@RequestAttribute Request requestModel, @@ -168,16 +183,14 @@ public ResponseEntity updateEntity(@RequestAttribute Request requestMo @ResponseBody @RequestMapping(value = "/update", method = RequestMethod.POST) - public ResponseEntity update(@RequestAttribute Request requestModel, - @PathVariable("id") String id) { + public ResponseEntity update(@RequestAttribute Request requestModel) { Model rdf = (Model) requestModel.getRequestMap().get("rdf"); - id = registryContext + id; ResponseParams responseParams = new ResponseParams(); Response response = new Response(Response.API_ID.UPDATE, "OK", responseParams); try { - registryService.updateEntity(rdf, id); + registryService.updateEntity(rdf, null); responseParams.setErrmsg(""); responseParams.setStatus(Response.Status.SUCCCESSFUL); } catch (RecordNotFoundException | EntityCreationException e) { @@ -186,7 +199,7 @@ public ResponseEntity update(@RequestAttribute Request requestModel, } catch (Exception e) { responseParams.setStatus(Response.Status.UNSUCCESSFUL); - responseParams.setErrmsg(String.format("Error occurred when updating Entity ID %s", id)); + responseParams.setErrmsg("Error occurred when updating Entity"); logger.error("ERROR!", e); } return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/java/registry/src/main/java/io/opensaber/registry/dao/RegistryDao.java b/java/registry/src/main/java/io/opensaber/registry/dao/RegistryDao.java index 982abf358..a34f8b4a0 100644 --- a/java/registry/src/main/java/io/opensaber/registry/dao/RegistryDao.java +++ b/java/registry/src/main/java/io/opensaber/registry/dao/RegistryDao.java @@ -14,7 +14,9 @@ public interface RegistryDao { public List getEntityList(); - public String addEntity(Graph entity, String label) throws DuplicateRecordException, EncryptionException, AuditFailedException; + public String addEntity(Graph entity, String label) throws DuplicateRecordException, EncryptionException, AuditFailedException, RecordNotFoundException; + + public String addEntity(Graph entity, String label, String rootNodeLabel, String property) throws DuplicateRecordException, RecordNotFoundException, NoSuchElementException, EncryptionException, AuditFailedException; public boolean updateEntity(Graph entityForUpdate, String rootNodeLabel, String methodOrigin) throws RecordNotFoundException, NoSuchElementException, EncryptionException, AuditFailedException; diff --git a/java/registry/src/main/java/io/opensaber/registry/dao/impl/RegistryDaoImpl.java b/java/registry/src/main/java/io/opensaber/registry/dao/impl/RegistryDaoImpl.java index 346b0953a..297dfa9ae 100644 --- a/java/registry/src/main/java/io/opensaber/registry/dao/impl/RegistryDaoImpl.java +++ b/java/registry/src/main/java/io/opensaber/registry/dao/impl/RegistryDaoImpl.java @@ -32,12 +32,14 @@ import io.opensaber.registry.exception.EncryptionException; import io.opensaber.registry.exception.RecordNotFoundException; import io.opensaber.registry.middleware.util.Constants; +import org.apache.commons.validator.routines.UrlValidator; @Component public class RegistryDaoImpl implements RegistryDao { public static final String META = "meta."; private static Logger logger = LoggerFactory.getLogger(RegistryDaoImpl.class); + @Autowired private DatabaseProvider databaseProvider; @@ -48,9 +50,6 @@ public class RegistryDaoImpl implements RegistryDao { @Value("${registry.context.base}") private String registryContext; - @Value("${registry.system.base}") - private String registrySystemContext; - @Autowired SchemaConfigurator schemaConfigurator; @@ -67,7 +66,7 @@ public List getEntityList() { } @Override - public String addEntity(Graph entity, String label) throws DuplicateRecordException, NoSuchElementException, EncryptionException, AuditFailedException{ + public String addEntity(Graph entity, String label) throws DuplicateRecordException, NoSuchElementException, EncryptionException, AuditFailedException, RecordNotFoundException{ logger.debug("Database Provider features: \n" + databaseProvider.getGraphStore().features()); Graph graphFromStore = databaseProvider.getGraphStore(); GraphTraversalSource traversalSource = graphFromStore.traversal(); @@ -82,6 +81,31 @@ public String addEntity(Graph entity, String label) throws DuplicateRecordExcept closeGraph(graphFromStore); return rootNodeLabel; } + + + @Override + public String addEntity(Graph entity, String label, String rootNodeLabel, String property) throws DuplicateRecordException, RecordNotFoundException, NoSuchElementException, EncryptionException, AuditFailedException{ + logger.debug("Database Provider features: \n" + databaseProvider.getGraphStore().features()); + Graph graphFromStore = databaseProvider.getGraphStore(); + GraphTraversalSource traversalSource = graphFromStore.traversal(); + if (rootNodeLabel!=null && property!=null && !traversalSource.clone().V().hasLabel(rootNodeLabel).hasNext()) { + closeGraph(graphFromStore); + throw new RecordNotFoundException(Constants.ENTITY_NOT_FOUND); + } else if (traversalSource.clone().V().hasLabel(label).hasNext()) { + closeGraph(graphFromStore); + throw new DuplicateRecordException(Constants.DUPLICATE_RECORD_MESSAGE); + } + + TinkerGraph graph = (TinkerGraph) entity; + label = createOrUpdateEntity(graph, label, "create"); + + if (rootNodeLabel!=null && property!=null){ + connectNodes(rootNodeLabel, label, property); + } + logger.info("Successfully created entity with label " + label); + closeGraph(graphFromStore); + return label; + } private void closeGraph(Graph graph) { try { @@ -90,6 +114,39 @@ private void closeGraph(Graph graph) { logger.error("Exception when closing the database graph", ex); } } + + private void connectNodes(String rootLabel, String label, String property) throws RecordNotFoundException, NoSuchElementException, EncryptionException, AuditFailedException { + Graph graphFromStore = databaseProvider.getGraphStore(); + GraphTraversalSource traversalSource = graphFromStore.traversal(); + + if (!traversalSource.clone().V().hasLabel(rootLabel).hasNext()) { + closeGraph(graphFromStore); + throw new RecordNotFoundException(Constants.ENTITY_NOT_FOUND); + } + + if (!traversalSource.clone().V().hasLabel(label).hasNext()) { + closeGraph(graphFromStore); + throw new RecordNotFoundException(Constants.ENTITY_NOT_FOUND); + } + + if (graphFromStore.features().graph().supportsTransactions()) { + org.apache.tinkerpop.gremlin.structure.Transaction tx = graphFromStore.tx(); + tx.onReadWrite(org.apache.tinkerpop.gremlin.structure.Transaction.READ_WRITE_BEHAVIOR.AUTO); + connectRootToEntity(traversalSource, rootLabel, label, property); + tx.commit(); + // tx.close(); + } else { + connectRootToEntity(traversalSource, rootLabel, label, property); + } + } + + private void connectRootToEntity(GraphTraversalSource dbTraversalSource, String rootLabel, String label, String property) throws RecordNotFoundException, NoSuchElementException, EncryptionException, AuditFailedException { + GraphTraversal rootGts = dbTraversalSource.clone().V().hasLabel(rootLabel); + GraphTraversal entityGts = dbTraversalSource.clone().V().hasLabel(label); + Vertex rootVertex = rootGts.next(); + Vertex entityVertex = entityGts.next(); + rootVertex.addEdge(property, entityVertex); + } /** * This method is commonly used for both create and update entity @@ -98,7 +155,7 @@ private void closeGraph(Graph graph) { * @throws EncryptionException * @throws NoSuchElementException */ - private String createOrUpdateEntity(Graph entity, String rootLabel, String methodOrigin) throws NoSuchElementException, EncryptionException, AuditFailedException{ + private String createOrUpdateEntity(Graph entity, String rootLabel, String methodOrigin) throws NoSuchElementException, EncryptionException, AuditFailedException, RecordNotFoundException{ Graph graphFromStore = databaseProvider.getGraphStore(); GraphTraversalSource dbGraphTraversalSource = graphFromStore.traversal(); @@ -134,7 +191,7 @@ private String createOrUpdateEntity(Graph entity, String rootLabel, String metho */ private String addOrUpdateVerticesAndEdges(GraphTraversalSource dbTraversalSource, GraphTraversalSource entitySource, String rootLabel, String methodOrigin) - throws NoSuchElementException, EncryptionException, AuditFailedException { + throws NoSuchElementException, EncryptionException, AuditFailedException, RecordNotFoundException { GraphTraversal gts = entitySource.clone().V().hasLabel(rootLabel); String label = rootLabel; @@ -151,9 +208,9 @@ private String addOrUpdateVerticesAndEdges(GraphTraversalSource dbTraversalSourc //} addOrUpdateVertexAndEdge(v, existingVertex, dbTraversalSource, methodOrigin); } else { - /*if(methodOrigin.equalsIgnoreCase("update")){ + if(methodOrigin.equalsIgnoreCase("update") && featureToggling){ throw new RecordNotFoundException(Constants.ENTITY_NOT_FOUND); - }*/ + } label = generateBlankNodeLabel(rootLabel); logger.info(String.format("Creating entity with label %s", rootLabel)); Vertex newVertex = dbTraversalSource.clone().addV(label).next(); @@ -174,7 +231,7 @@ private String addOrUpdateVerticesAndEdges(GraphTraversalSource dbTraversalSourc * @throws NoSuchElementException */ private void addOrUpdateVertexAndEdge(Vertex v, Vertex dbVertex, GraphTraversalSource dbGraph, String methodOrigin) - throws NoSuchElementException, EncryptionException, AuditFailedException{ + throws NoSuchElementException, EncryptionException, AuditFailedException, RecordNotFoundException{ Iterator edges = v.edges(Direction.OUT); Stack> parsedVertices = new Stack<>(); List dbEdgesForVertex = ImmutableList.copyOf(dbVertex.edges(Direction.OUT)); @@ -185,7 +242,6 @@ private void addOrUpdateVertexAndEdge(Vertex v, Vertex dbVertex, GraphTraversalS GraphTraversal gt = dbGraph.clone().V().hasLabel(ver.label()); if (gt.hasNext()) { - //if(!methodOrigin.equalsIgnoreCase("upsert")){ Vertex existingV = gt.next(); logger.info(String.format("Vertex with label %s already exists. Updating properties for the vertex", existingV.label())); copyProperties(ver, existingV,methodOrigin); @@ -204,11 +260,10 @@ private void addOrUpdateVertexAndEdge(Vertex v, Vertex dbVertex, GraphTraversalS .record(databaseProvider); } parsedVertices.push(new Pair<>(ver, existingV)); - //} } else { - /*if(methodOrigin.equalsIgnoreCase("update") && isBlankNode(ver.label())){ + if(methodOrigin.equalsIgnoreCase("update") && !isIRI(ver.label()) && featureToggling){ throw new RecordNotFoundException(Constants.ENTITY_NOT_FOUND); - }*/ + } String label = generateBlankNodeLabel(ver.label()); Vertex newV = dbGraph.addV(label).next(); logger.info(String.format("Adding vertex with label %s and adding properties", newV.label())); @@ -241,7 +296,7 @@ private void addOrUpdateVertexAndEdge(Vertex v, Vertex dbVertex, GraphTraversalS * @return */ private String generateBlankNodeLabel(String label) { - if(isBlankNode(label)) { + if(!isIRI(label)){ label = String.format("%s%s", registryContext, generateRandomUUID()); } return label; @@ -253,6 +308,14 @@ private boolean isBlankNode(String label){ } return false; } + + private boolean isIRI(String label){ + UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); + if(urlValidator.isValid(label)) { + return true; + } + return false; + } public static String generateRandomUUID() { return UUID.randomUUID().toString(); @@ -345,7 +408,7 @@ private void setProperty(Vertex v, String key, Object newValue, String methodOri Object oldValue = vp.isPresent() ? vp.value() : null; if(RDFUtil.isSingleValued(key)){ v.property(key, newValue); - }else if(featureToggling && methodOrigin.equalsIgnoreCase("add")){ + }/*else if(featureToggling){ if(vp.isPresent()){ Object value = vp.value(); List valueList = new ArrayList(); @@ -360,7 +423,7 @@ private void setProperty(Vertex v, String key, Object newValue, String methodOri }else{ v.property(key, newValue); } - }else{ + }*/else{ v.property(key, newValue); } if (!isaMetaProperty(key) && !Objects.equals(oldValue, newValue)) { diff --git a/java/registry/src/main/java/io/opensaber/registry/service/RegistryService.java b/java/registry/src/main/java/io/opensaber/registry/service/RegistryService.java index dab8ca680..0177fec27 100644 --- a/java/registry/src/main/java/io/opensaber/registry/service/RegistryService.java +++ b/java/registry/src/main/java/io/opensaber/registry/service/RegistryService.java @@ -7,15 +7,15 @@ import io.opensaber.pojos.HealthCheckResponse; import io.opensaber.registry.exception.*; import org.apache.jena.rdf.model.Model; -import org.springframework.boot.actuate.health.Health; public interface RegistryService { public List getEntityList(); - public String addEntity(Model rdfModel) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException; + public String addEntity(Model rdfModel) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException; - public String addToExistingEntity(Model rdfModel, String subject, String property) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException; + public String addEntity(Model rdfModel, String subject, String property) throws DuplicateRecordException, EntityCreationException, + EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException; public boolean updateEntity(Model entity, String rootNodeLabel) throws RecordNotFoundException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException; @@ -25,7 +25,7 @@ public interface RegistryService { public HealthCheckResponse health() throws Exception; - public String frameEntity(org.eclipse.rdf4j.model.Model entityModel) throws IOException; + public String frameEntity(org.eclipse.rdf4j.model.Model entityModel) throws IOException, MultipleEntityException, EntityCreationException; public String frameAuditEntity(org.eclipse.rdf4j.model.Model entityModel) throws IOException; diff --git a/java/registry/src/main/java/io/opensaber/registry/service/impl/RegistryServiceImpl.java b/java/registry/src/main/java/io/opensaber/registry/service/impl/RegistryServiceImpl.java index 73da0e3cd..26ccaa716 100644 --- a/java/registry/src/main/java/io/opensaber/registry/service/impl/RegistryServiceImpl.java +++ b/java/registry/src/main/java/io/opensaber/registry/service/impl/RegistryServiceImpl.java @@ -18,6 +18,7 @@ import org.apache.jena.rdf.model.RDFNode; import org.apache.jena.rdf.model.ResIterator; import org.apache.jena.rdf.model.Resource; +import org.apache.jena.rdf.model.ResourceFactory; import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.riot.JsonLDWriteContext; @@ -69,34 +70,8 @@ public List getEntityList(){ } @Override - public String addEntity(Model rdfModel) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException { + public String addEntity(Model rdfModel) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException { try { - /*Graph graph = GraphDBFactory.getEmptyGraph(); - StmtIterator iterator = rdfModel.listStatements(); - boolean rootSubjectFound = false; - boolean rootNodeBlank = false; - String label = null; - - while (iterator.hasNext()) { - Statement rdfStatement = iterator.nextStatement(); - if (!rootSubjectFound) { - String type = environment.getProperty(Constants.SUBJECT_LABEL_TYPE); - label = RDF2Graph.getRootSubjectLabel(rdfStatement, type); - if (label != null) { - rootSubjectFound = true; - if(rdfStatement.getSubject().isAnon() && rdfStatement.getSubject().getURI() == null) { - rootNodeBlank = true; - } - } - } - org.eclipse.rdf4j.model.Statement rdf4jStatement = JenaRDF4J.asrdf4jStatement(rdfStatement); - graph = RDF2Graph.convertRDFStatement2Graph(rdf4jStatement, graph); - } - if (label == null) { - throw new InvalidTypeException(Constants.INVALID_TYPE_MESSAGE); - }*/ - - // Append _: to the root node label to create the entity as Apache Jena removes the _: for the root node label // if it is a blank node String label = getRootLabel(rdfModel); @@ -112,40 +87,17 @@ public String addEntity(Model rdfModel) throws DuplicateRecordException, EntityC } @Override - public String addToExistingEntity(Model rdfModel, String subject, String property) throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException { + public String addEntity(Model rdfModel, String subject, String property) throws DuplicateRecordException, EntityCreationException, + EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException { try { String label = getRootLabel(rdfModel); Graph graph = generateGraphFromRDF(rdfModel); - /*if((label == null) && featureToggling){ - StmtIterator stmtIter = rdfModel.listStatements(); - List subjectList = new ArrayList(); - List subjectWithTypeList = new ArrayList(); - while (stmtIter.hasNext()) { - Statement rdfStatement = stmtIter.nextStatement(); - Resource subject = rdfStatement.getSubject(); - subjectList.add(subject.toString()); - String predicate = rdfStatement.getPredicate().toString(); - if(predicate.equals(RDF.TYPE.toString())){ - subjectWithTypeList.add(subject.toString()); - } - org.eclipse.rdf4j.model.Statement rdf4jStatement = JenaRDF4J.asrdf4jStatement(rdfStatement); - graph = RDF2Graph.convertRDFStatement2Graph(rdf4jStatement, graph); - } - for(String sub : subjectWithTypeList){ - if(subjectList.contains(sub)){ - subjectList.remove(sub); - } - } - if(subjectList.size()>0){ - label = subjectList.get(0); - } - }*/ // Append _: to the root node label to create the entity as Apache Jena removes the _: for the root node label // if it is a blank node - return registryDao.addEntity(graph, label); + return registryDao.addEntity(graph, label, subject, property); - } catch (DuplicateRecordException | EntityCreationException | EncryptionException | AuditFailedException ex) { + } catch (EntityCreationException | EncryptionException | AuditFailedException ex) { throw ex; } catch (Exception ex) { logger.error("Exception when creating entity: ", ex); @@ -164,13 +116,6 @@ public boolean updateEntity(Model entity, String rootNodeLabel) throws RecordNot @Override public org.eclipse.rdf4j.model.Model getEntityById(String label) throws RecordNotFoundException, EncryptionException, AuditFailedException { Graph graph = registryDao.getEntityById(label); - /* - try { - graph.io(graphson()).writeGraph("graph.json"); - } catch (IOException e) { - e.printStackTrace(); - } - */ org.eclipse.rdf4j.model.Model model = RDF2Graph.convertGraph2RDFModel(graph, label); for (org.eclipse.rdf4j.model.Statement statement : model) { logger.debug("STATEMENT " + statement); @@ -213,12 +158,15 @@ public HealthCheckResponse health() throws Exception { } @Override - public String frameEntity(org.eclipse.rdf4j.model.Model entityModel) throws IOException { + public String frameEntity(org.eclipse.rdf4j.model.Model entityModel) throws IOException, MultipleEntityException, EntityCreationException { Model jenaEntityModel = JenaRDF4J.asJenaModel(entityModel); + String rootLabel = getRootLabel(jenaEntityModel); + String rootLabelType = getTypeForRootLabel(jenaEntityModel, rootLabel); DatasetGraph g = DatasetFactory.create(jenaEntityModel).asDatasetGraph(); JsonLDWriteContext ctx = new JsonLDWriteContext(); InputStream is = this.getClass().getClassLoader().getResourceAsStream("frame.json"); String fileString = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8); + fileString = fileString.replace("<@type>", rootLabelType); ctx.setFrame(fileString); WriterDatasetRIOT w = RDFDataMgr.createDatasetWriter(org.apache.jena.riot.RDFFormat.JSONLD_FRAME_FLAT) ; PrefixMap pm = RiotLib.prefixMap(g); @@ -256,28 +204,6 @@ public org.eclipse.rdf4j.model.Model getAuditNode(String id) throws IOException, } private Graph generateGraphFromRDF(Model entity) throws EntityCreationException, MultipleEntityException{ - /*Graph graph = GraphDBFactory.getEmptyGraph(); - - StmtIterator iterator = entity.listStatements(); - boolean rootSubjectFound = false; - String label = null; - - while (iterator.hasNext()) { - Statement rdfStatement = iterator.nextStatement(); - if (!rootSubjectFound) { - String type = environment.getProperty(Constants.SUBJECT_LABEL_TYPE); - label = RDF2Graph.getRootSubjectLabel(rdfStatement, type); - if (label != null) { - rootSubjectFound = true; - } - } - org.eclipse.rdf4j.model.Statement rdf4jStatement = JenaRDF4J.asrdf4jStatement(rdfStatement); - graph = RDF2Graph.convertRDFStatement2Graph(rdf4jStatement, graph); - } - - if (label == null) { - throw new InvalidTypeException(Constants.INVALID_TYPE_MESSAGE); - }*/ Graph graph = GraphDBFactory.getEmptyGraph(); StmtIterator iterator = entity.listStatements(); while (iterator.hasNext()) { @@ -303,4 +229,15 @@ private String getRootLabel(Model entity) throws EntityCreationException, Multip return label; } } + + private String getTypeForRootLabel(Model entity, String rootLabel) throws EntityCreationException, MultipleEntityException{ + List rootLabelType = RDFUtil.getTypeForSubject(entity, rootLabel); + if(rootLabelType.size() == 0){ + throw new EntityCreationException(Constants.NO_ENTITY_AVAILABLE_MESSAGE); + } else if(rootLabelType.size() > 1){ + throw new MultipleEntityException(Constants.ADD_UPDATE_MULTIPLE_ENTITIES_MESSAGE); + } else{ + return rootLabelType.get(0); + } + } } diff --git a/java/registry/src/main/java/io/opensaber/registry/util/RDFUtil.java b/java/registry/src/main/java/io/opensaber/registry/util/RDFUtil.java index dc2c1a192..ea97bbd9d 100644 --- a/java/registry/src/main/java/io/opensaber/registry/util/RDFUtil.java +++ b/java/registry/src/main/java/io/opensaber/registry/util/RDFUtil.java @@ -10,6 +10,7 @@ import org.apache.jena.riot.system.PrefixMap; import org.apache.jena.riot.system.RiotLib; import org.apache.jena.sparql.core.DatasetGraph; +import org.apache.jena.vocabulary.RDF; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.T; import org.slf4j.Logger; @@ -181,5 +182,16 @@ public static List getRootLabels(Model rdfModel){ } return rootLabelList; } + + public static List getTypeForSubject(Model rdfModel, String label){ + List typeIRIs = new ArrayList(); + Resource subject = ResourceFactory.createResource(label); + NodeIterator nodeIter = rdfModel.listObjectsOfProperty(subject, RDF.type); + while(nodeIter.hasNext()){ + RDFNode rdfNode = nodeIter.next(); + typeIRIs.add(rdfNode.toString()); + } + return typeIRIs; + } } diff --git a/java/registry/src/main/resources/audit_frame.json b/java/registry/src/main/resources/audit_frame.json index 6247a2b13..38eb5a938 100644 --- a/java/registry/src/main/resources/audit_frame.json +++ b/java/registry/src/main/resources/audit_frame.json @@ -2,7 +2,7 @@ "@context": { "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", - "teacher": "http://example.com/voc/teacher/1.0.0/", + "teacher": "http://localhost:8080/", "xsd": "http://www.w3.org/2001/XMLSchema#" } } \ No newline at end of file diff --git a/java/registry/src/test/java/io/opensaber/registry/controller/RegistryControllerTest.java b/java/registry/src/test/java/io/opensaber/registry/controller/RegistryControllerTest.java index 1886c2912..40637ef39 100644 --- a/java/registry/src/test/java/io/opensaber/registry/controller/RegistryControllerTest.java +++ b/java/registry/src/test/java/io/opensaber/registry/controller/RegistryControllerTest.java @@ -23,7 +23,6 @@ import static org.mockito.Mockito.when; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; @@ -37,6 +36,7 @@ import io.opensaber.registry.exception.EncryptionException; import io.opensaber.registry.exception.EntityCreationException; import io.opensaber.registry.exception.MultipleEntityException; +import io.opensaber.registry.exception.RecordNotFoundException; import io.opensaber.registry.middleware.util.Constants; import io.opensaber.registry.model.AuditRecord; import io.opensaber.registry.schema.config.SchemaConfigurator; @@ -109,7 +109,7 @@ public void initialize() { } @Test - public void test_adding_a_new_record() throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException{ + public void test_adding_a_new_record() throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException{ Model model = getNewValidRdf(VALID_JSONLD, CONTEXT_CONSTANT); registryService.addEntity(model); assertEquals(5, @@ -119,7 +119,7 @@ public void test_adding_a_new_record() throws DuplicateRecordException, EntityCr } @Test - public void test_adding_duplicate_record() throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException { + public void test_adding_duplicate_record() throws DuplicateRecordException, EntityCreationException, EncryptionException, AuditFailedException, MultipleEntityException, RecordNotFoundException { expectedEx.expect(DuplicateRecordException.class); expectedEx.expectMessage(Constants.DUPLICATE_RECORD_MESSAGE); Model model = getNewValidRdf(VALID_JSONLD, CONTEXT_CONSTANT); diff --git a/java/registry/src/test/java/io/opensaber/registry/dao/impl/RegistryDaoImplTest.java b/java/registry/src/test/java/io/opensaber/registry/dao/impl/RegistryDaoImplTest.java index 4cb465b09..1902aaf7e 100644 --- a/java/registry/src/test/java/io/opensaber/registry/dao/impl/RegistryDaoImplTest.java +++ b/java/registry/src/test/java/io/opensaber/registry/dao/impl/RegistryDaoImplTest.java @@ -99,9 +99,6 @@ public class RegistryDaoImplTest extends RegistryTestBase { @Autowired AuditRecordReader auditRecordReader; - - @Value("${registry.system.base}") - private String registrySystemContext; private static String identifier; @@ -157,7 +154,7 @@ public void test_adding_a_single_node() throws DuplicateRecordException, RecordN String response = registryDao.addEntity(graph, label); Graph entity = registryDao.getEntityById(response); assertEquals(1, IteratorUtils.count(entity.traversal().clone().V())); - Vertex v = entity.traversal().V().has(T.label, label).next(); + Vertex v = entity.traversal().V().has(T.label, response).next(); assertEquals("DAV Public School", v.property("http://example.com/voc/teacher/1.0.0/schoolName").value()); checkIfAuditRecordsAreRight(entity, null); }