Added PATCH method [#24985]

This commit is contained in:
Francesco Mangiacrapa 2023-04-26 12:28:14 +02:00
parent 988fe9b4fe
commit 194b083f4e
3 changed files with 190 additions and 1 deletions

View File

@ -1,5 +1,8 @@
# Changelog for org.gcube.application.geoportal-client
## [v1.2.0-SNAPSHOT] - 2023-04-26
- Added PATCH method [#24985]
## [v1.1.2] - 2023-01-10
- Pom updates

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-client</artifactId>
<version>1.1.2</version>
<version>1.2.0-SNAPSHOT</version>
<name>Geoportal Client</name>

View File

@ -15,14 +15,24 @@ import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.rest.Projects;
import org.gcube.common.clients.Call;
import org.gcube.common.clients.delegates.ProxyDelegate;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.Iterator;
/**
* Instantiates a new default documents client.
*
* @param delegate the delegate
* @param profileID the profile ID
* @param managedClass the managed class
*/
@RequiredArgsConstructor
@Slf4j
public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
@ -35,10 +45,22 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
protected final Class<T> managedClass;
/**
* Gets the managed class.
*
* @return the managed class
*/
public Class<T> getManagedClass() {
return managedClass;
}
/**
* Creates the new.
*
* @param toCreate the to create
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T createNew(Document toCreate) throws RemoteException {
try {
@ -60,11 +82,24 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Delete by id.
*
* @param id the id
* @throws RemoteException the remote exception
*/
@Override
public void deleteById(String id) throws RemoteException {
deleteById(id,false);
}
/**
* Delete by id.
*
* @param id the id
* @param force the force
* @throws RemoteException the remote exception
*/
@Override
public void deleteById(String id, Boolean force) throws RemoteException {
try {
@ -85,6 +120,13 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Gets the by id.
*
* @param id the id
* @return the by id
* @throws RemoteException the remote exception
*/
@Override
public T getById(String id) throws RemoteException {
try {
@ -104,6 +146,12 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Gets the configuration.
*
* @return the configuration
* @throws RemoteException the remote exception
*/
@Override
public Configuration getConfiguration() throws RemoteException {
try {
@ -122,11 +170,27 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Query.
*
* @param request the request
* @return the iterator
* @throws RemoteException the remote exception
*/
@Override
public Iterator<T> query(QueryRequest request) throws RemoteException {
return queryForClass(request,getManagedClass());
}
/**
* Query for class.
*
* @param <C> the generic type
* @param request the request
* @param clazz the clazz
* @return the iterator
* @throws RemoteException the remote exception
*/
@Override
public <C> Iterator<C> queryForClass(QueryRequest request,Class<C> clazz) throws RemoteException {
String jsonString=queryForJSON(request);
@ -141,6 +205,13 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Query for JSON.
*
* @param request the request
* @return the string
* @throws RemoteException the remote exception
*/
@Override
public String queryForJSON(QueryRequest request) throws RemoteException {
try {
@ -159,6 +230,14 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Perform step.
*
* @param id the id
* @param request the request
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T performStep(String id, StepExecutionRequest request) throws RemoteException{
try {
@ -182,6 +261,15 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Register file set.
*
* @param id the id
* @param req the req
* @return the t
* @throws RemoteException the remote exception
* @throws InvalidRequestException the invalid request exception
*/
@Override
public T registerFileSet(String id, RegisterFileSetRequest req) throws RemoteException, InvalidRequestException {
try {
@ -209,6 +297,15 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Delete file set.
*
* @param id the id
* @param path the path
* @param force the force
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T deleteFileSet(String id, String path, Boolean force) throws RemoteException {
try {
@ -232,6 +329,13 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Force unlock.
*
* @param id the id
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T forceUnlock(String id) throws RemoteException {
try {
@ -254,6 +358,14 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Sets the access policy.
*
* @param id the id
* @param toSet the to set
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T setAccessPolicy(String id, Access toSet) throws RemoteException {
try {
@ -276,6 +388,14 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Update document.
*
* @param id the id
* @param updatedDocument the updated document
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T updateDocument(String id, Document updatedDocument) throws RemoteException {
try {
@ -298,6 +418,48 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Patch document.
* Added by Francesco Mangiacrapa
*
* @param id the id
* @param path the path
* @param updatedDocument the updated document
* @return the t
* @throws RemoteException the remote exception
*/
@Override
public T patchDocument(String id, String path, Document updatedDocument) throws RemoteException {
try {
log.debug("Patching {} [useCaseDescriptor {} , class {}] with ", id, profileID, getManagedClass(),
updatedDocument);
Call<WebTarget, T> call = endpoint -> {
WebTarget webTarget = endpoint.path(profileID).path(id);
webTarget.queryParam(InterfaceConstants.Parameters.PATH, path);
webTarget.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
Response response = webTarget.request(MediaType.APPLICATION_JSON).method("PATCH", Entity.entity(updatedDocument, MediaType.APPLICATION_JSON));
return ResponseCommons.check(response, getManagedClass());
};
T toReturn = delegate.make(call);
log.info("Updated ID {} useCaseDescriptor {}", id, profileID);
return toReturn;
} catch (RemoteException e) {
log.error("Unexpected error ", e);
throw e;
} catch (Exception e) {
log.error("Unexpected error ", e);
throw new RemoteException("Unexpected Error", e);
}
}
/**
* Sets the relation.
*
* @param request the request
* @return the project
* @throws RemoteException the remote exception
*/
@Override
public Project setRelation(CreateRelationshipRequest request) throws RemoteException {
try {
@ -328,6 +490,13 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Delete relation.
*
* @param request the request
* @return the project
* @throws RemoteException the remote exception
*/
@Override
public Project deleteRelation(DeleteRelationshipRequest request) throws RemoteException {
try {
@ -358,11 +527,28 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
}
}
/**
* Gets the relationship chain.
*
* @param id the id
* @param relationId the relation id
* @return the relationship chain
* @throws RemoteException the remote exception
*/
@Override
public Iterator<RelationshipNavigationObject> getRelationshipChain(String id, String relationId) throws RemoteException {
return getRelationshipChain(id,relationId,null);
}
/**
* Gets the relationship chain.
*
* @param id the id
* @param relationId the relation id
* @param deep the deep
* @return the relationship chain
* @throws RemoteException the remote exception
*/
@Override
public Iterator<RelationshipNavigationObject> getRelationshipChain(String id, String relationId, Boolean deep) throws RemoteException {
try {