Check on get Mandatory

This commit is contained in:
Fabio Sinibaldi 2022-05-31 16:10:41 +02:00
parent 521b5c90a6
commit ab4a8ef1dc
4 changed files with 15 additions and 4 deletions

View File

@ -1,9 +1,11 @@
package org.gcube.application.cms.plugins.requests;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ser.Serializers;
import lombok.*;
import org.bson.Document;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
import org.gcube.application.geoportal.common.model.document.accounting.Context;
import org.gcube.application.geoportal.common.model.document.accounting.User;
@ -39,7 +41,11 @@ public class BaseRequest {
public static final String getMandatory(String param,Document params) throws InvalidPluginRequestException {
if(params==null || params.isEmpty()|| !params.containsKey(param)) throw new InvalidPluginRequestException("Missing mandatory parameter "+param);
return params.getString(param);
try {
return Serialization.write(params.get(param));
} catch (JsonProcessingException e) {
throw new InvalidPluginRequestException(e);
}
}
public BaseRequest validate() throws InvalidPluginRequestException {

View File

@ -874,6 +874,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
log.info("[UseCaseDescriptor {}] triggering event {} on {}" , useCaseDescriptor.getId(),event,getManager().getDescriptor());
AccountingInfo user= UserUtils.getCurrent().asInfo();
EventExecutionRequest request= new EventExecutionRequest(useCaseDescriptor,user.getUser(),user.getContext(),project,event);
request.setCallParameters(parameters);
log.debug("Triggering {}",request);
DocumentHandlingReport report = getManager().onEvent(request);
return report.prepareResult();

View File

@ -98,7 +98,11 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
}
protected void delete(String id) throws Exception {
check(baseTarget().path(id).request(MediaType.APPLICATION_JSON).
delete(id,false);
}
protected void delete(String id,Boolean force) throws Exception {
check(baseTarget().path(id).queryParam("force",force).request(MediaType.APPLICATION_JSON).
delete(), null);
}

View File

@ -75,7 +75,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
@Test
public void testDelete() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
delete(createWithFileSet().getId());
delete(createWithFileSet().getId(),true);
}