Validate the parent exists in the create operation, if specified in the input context.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162406 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Manuele Simi 6 years ago
parent 97e9f88f70
commit eb900141e2

@ -5,6 +5,7 @@ import java.util.Objects;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextAlreadyPresentException;
import org.gcube.resourcemanagement.manager.io.codeexceptions.LocalCodeException;
import org.gcube.resourcemanagement.manager.io.codeexceptions.WebCodeException;
import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode;
@ -31,12 +32,13 @@ public final class CreateRequest extends RequestToResourceRegistry {
* @see org.gcube.resourcemanagement.manager.webapp.context.RequestToResourceRegistry#validate()
*/
@Override
public CreateRequest validate() throws Exception {
//TODO: to implement
public void validate() throws LocalCodeException {
if (Objects.nonNull(this.context.getParent())) {
throw new Exception("Unable to manage a context with parent.");
Context parent = new Queries().fetchContext(this.context.getParent().getHeader().getUUID(), this.getContextClient());
if (Objects.isNull(parent)) {
throw new LocalCodeException(RMCreateContextCode.CONTEXT_PARENT_DOES_NOT_EXIST);
}
}
return this;
}
/* (non-Javadoc)
@ -45,7 +47,7 @@ public final class CreateRequest extends RequestToResourceRegistry {
@Override
protected ResponseFromResourceRegistry send() {
try {
Context created = resourceRegistryContextClient.create(context);
Context created = this.getContextClient().create(context);
if (Objects.nonNull(created)) {
} else {

Loading…
Cancel
Save