fixing HTTP response codes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-api@146756 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-04-11 13:23:11 +00:00
parent 9921fd60b5
commit ee4b037c96
2 changed files with 27 additions and 8 deletions

View File

@ -14,6 +14,7 @@ public class AccessPath {
public static final String LIMIT_PARAM = "limit";
public static final String FETCH_PLAN_PARAM = "fetchPlan";
public static final int UNBOUNDED = -1;
public static final int DEFAULT_LIMIT = 20;
public static final String FACET_PATH_PART = ERPath.FACET_PATH_PART;

View File

@ -22,9 +22,13 @@ import org.gcube.informationsystem.model.entity.Resource;
import org.gcube.informationsystem.model.relation.Relation;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ExceptionMapper;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -163,21 +167,32 @@ public class HTTPCall {
return result;
}
protected <C> void throwElementNotFoundException(Class<C> clz)
protected <C> ERNotFoundException getElementNotFoundException(Class<C> clz)
throws ERNotFoundException, ResourceRegistryException {
String error = String.format("Requested %s instance was not found", clz.getSimpleName());
if (Resource.class.isAssignableFrom(clz)) {
throw new ResourceNotFoundException(error);
return new ResourceNotFoundException(error);
} else if (Facet.class.isAssignableFrom(clz)) {
throw new FacetNotFoundException(error);
return new FacetNotFoundException(error);
} else if (Relation.class.isAssignableFrom(clz)) {
throw new RelationNotFoundException(error);
return new RelationNotFoundException(error);
}
return new ERNotFoundException(error);
}
protected <C> ERAvailableInAnotherContextException getElementAvailableInAnotherContextException(Class<C> clz) {
String error = String.format("Requested %s instance was not found", clz.getSimpleName());
if (Resource.class.isAssignableFrom(clz)) {
return new ResourceAvailableInAnotherContextException(error);
} else if (Facet.class.isAssignableFrom(clz)) {
return new FacetAvailableInAnotherContextException(error);
} else if (Relation.class.isAssignableFrom(clz)) {
return new RelationAvailableInAnotherContextException(error);
}
return new ERAvailableInAnotherContextException(error);
}
public <C> C call(Class<C> clz, String path, HTTPMETHOD method) throws Exception {
return call(clz, path, method, null, null);
}
@ -209,7 +224,10 @@ public class HTTPCall {
return null;
}
if(responseCode == HttpURLConnection.HTTP_NOT_FOUND){
throwElementNotFoundException(clz);
throw getElementNotFoundException(clz);
}
if(responseCode == HttpURLConnection.HTTP_CONFLICT){
throw getElementAvailableInAnotherContextException(clz);
}
}