@Override protected final ResourceId id() { return endpoint().resourceId(); }
Resource resolveResource(Endpoint endpoint) { return loadResource(endpoint.resourceId()); }
/** * {@inheritDoc} */ @Override public void add(Endpoint endpoint) { this.writeLock.lock(); try { if(this.endpointsByPath.containsKey(endpoint.path())) { throw new IllegalArgumentException("An endpoint with path '"+endpoint.path()+"' already exists"); } Endpoint other=endpointOfResource(endpoint.resourceId()); if(other!=null) { throw new IllegalArgumentException("An endpoint with resource name '"+endpoint.resourceId()+"' already exists ("+other+")"); } this.endpointsByPath.put(endpoint.path(), endpoint); this.endpointsByResourceName.put(endpoint.resourceId(),endpoint); } finally { this.writeLock.unlock(); } }
void registerContentFailure(Endpoint endpoint, InvalidContentException error) { registerConstraintReport(loadResource(endpoint.resourceId()),error); }
@Override public void execute(EndpointRepository sut) { Endpoint result = sut.endpointOfResource(ep1.resourceId()); System.out.println(result); } }
private boolean isSelf(ManagedIndividualId id) { ResourceId resourceId = super.endpoint().resourceId(); return id.managerId().equals(resourceId.templateId()) && id.name().equals(resourceId.name()); }
DataSet getConstraintReport(Endpoint endpoint, String constraintsId) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); // TODO: Check if it is really necessary Resource resource = loadResource(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_RESOURCE_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } ConstraintReport report= this.constraintReportRepository. constraintReportOfId( ConstraintReportId. create(resource.id(),constraintsId)); if(report==null) { return null; } return ConstraintReportTransformer. create(resource, report). transform(endpoint); }
private void publish(RootResource rootResource, Date creationDate) throws ApplicationConfigurationException { ResourceId resourceId = rootResource.resourceId(); String path = rootResource.path(); Resource prevResource = this.resourceRepository.resourceById(resourceId,Resource.class); Endpoint prevEndpoint = this.endpointRepository.endpointOfPath(path); if(prevEndpoint!=null && !prevEndpoint.resourceId().equals(resourceId)) { throw new ApplicationConfigurationException(String.format("Resource %s cannot be published at '%s' as that path is already in use by a resource %s",toString(resourceId),path,toString(prevEndpoint.resourceId()))); } if(prevEndpoint==null) { if(prevResource!=null) { throw new ApplicationConfigurationException(String.format("Resource %s cannot be published at '%s' as it is already published at '%s'",toString(resourceId),path,this.endpointRepository.endpointOfResource(resourceId).path())); } else { Resource resource=this.modelFactory.createResource(rootResource.template(),rootResource.name()); this.resourceRepository.add(resource); Endpoint endpoint=this.modelFactory.createEndpoint(path,resource,creationDate,EntityTag.createStrong(path)); this.endpointRepository.add(endpoint); } } }
DataSet getResource(Endpoint endpoint) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); Resource resource = loadResource(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_RESOURCE_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } try { WriteSessionConfiguration config= DefaultApplicationContextHelper. create(this.engine().templateManagementService()). createConfiguration(resource,lastModified()); return this.engine().resourceControllerService().getResource(resource,config); } catch (Exception e) { String errorMessage = applicationFailureMessage(RESOURCE_RETRIEVAL_FAILED,endpoint); throw createException(errorMessage,e); } }
void deleteResource(Endpoint endpoint) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); Resource resource = loadResource(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_CONTAINER_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } try { WriteSessionConfiguration config= DefaultApplicationContextHelper. create(this.engine().templateManagementService()). createConfiguration(resource,lastModified()); this.engine().resourceControllerService().deleteResource(resource,config); } catch (Exception e) { String errorMessage = applicationFailureMessage(RESOURCE_DELETION_FAILED,endpoint); throw createException(errorMessage,e); } }
DataSet query(Endpoint endpoint, Query query) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); Resource resource = loadResource(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_RESOURCE_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } try { WriteSessionConfiguration config= DefaultApplicationContextHelper. create(this.engine().templateManagementService()). createConfiguration(resource,lastModified()); return this.engine().resourceControllerService().queryResource(resource,query,config); } catch (Exception e) { String errorMessage = applicationFailureMessage(RESOURCE_QUERY_FAILED,endpoint); throw createException(errorMessage,e); } }
void modifyResource(Endpoint endpoint, DataSet dataSet) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); Resource resource = loadResource(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_RESOURCE_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } try { WriteSessionConfiguration config= DefaultApplicationContextHelper. create(this.engine().templateManagementService()). createConfiguration(resource,lastModified()); this.engine().resourceControllerService().updateResource(resource,dataSet,config); } catch (FeatureExecutionException e) { processConstraintValidationFailure(resource, e); String errorMessage = applicationFailureMessage(RESOURCE_MODIFICATION_FAILED,endpoint); throw createException(errorMessage,e); } catch (Exception e) { String errorMessage = applicationFailureMessage(RESOURCE_MODIFICATION_FAILED,endpoint); throw createException(errorMessage,e); } }
Resource createResource(Endpoint endpoint, DataSet dataSet, String desiredPath) throws ApplicationExecutionException { ResourceId resourceId=endpoint.resourceId(); Container resource = this.resourceRepository.containerOfId(resourceId); if(resource==null) { String errorMessage = applicationFailureMessage(COULD_NOT_FIND_CONTAINER_FOR_ENDPOINT,endpoint); LOGGER.error(errorMessage); throw new ApplicationExecutionException(errorMessage); } try { WriteSessionConfiguration config= DefaultApplicationContextHelper. create(this.engine().templateManagementService()). createConfiguration(resource,dataSet,desiredPath,lastModified()); return this.engine().resourceControllerService().createResource(resource,dataSet,config); } catch (FeatureExecutionException e) { processConstraintValidationFailure(resource, e); String errorMessage = applicationFailureMessage(RESOURCE_CREATION_FAILED,endpoint); throw createException(errorMessage,e); } catch (InvalidIndirectIdentifierException e) { // Just rethrow throw e; } catch (Exception e) { String errorMessage = applicationFailureMessage(RESOURCE_CREATION_FAILED,endpoint); throw createException(errorMessage,e); } }