Testing
This commit is contained in:
parent
b810bbb3ed
commit
70f427d67b
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.application.cms.plugins.implementations;
|
package org.gcube.application.cms.plugins.implementations;
|
||||||
|
|
||||||
|
import com.sun.xml.internal.ws.client.HandlerConfiguration;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.gcube.application.cms.plugins.LifecycleManager;
|
import org.gcube.application.cms.plugins.LifecycleManager;
|
||||||
|
@ -110,22 +111,28 @@ public abstract class AbstractLifeCycleManager extends AbstractPlugin implements
|
||||||
@Override
|
@Override
|
||||||
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException, InvalidProfileException, ConfigurationException, InsufficientPrivileges {
|
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException, InvalidPluginRequestException, InvalidProfileException, ConfigurationException, InsufficientPrivileges {
|
||||||
log.info("Serving Request {}",request);
|
log.info("Serving Request {}",request);
|
||||||
StepExecutionReport report=new StepExecutionReport(request);
|
|
||||||
report.setStatus(Report.Status.OK);
|
|
||||||
LifecycleInformation info=report.getToSetLifecycleInformation();
|
|
||||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
|
||||||
info.setLastInvokedStep(request.getStep());
|
|
||||||
|
|
||||||
if(!canInvokeStep(request.getStep(),request.getCaller(),
|
|
||||||
getConfigurationFromProfile(request.getUseCaseDescriptor())))
|
|
||||||
throw new InsufficientPrivileges("User is not allowed to invoke "+request.getStep());
|
|
||||||
|
|
||||||
|
log.debug("Checking is STEP {} is supported by {}",request.getStep(),DESCRIPTOR.getId());
|
||||||
if(!registeredSteps.containsKey(request.getStep()))
|
if(!registeredSteps.containsKey(request.getStep()))
|
||||||
throw new UnrecognizedStepException(("Invalid Step " + request.getStep()));
|
throw new UnrecognizedStepException(("Invalid Step " + request.getStep()));
|
||||||
|
|
||||||
|
HandlerDeclaration handlerDeclaration= getConfigurationFromProfile(request.getUseCaseDescriptor());
|
||||||
|
log.debug("Checking user role {} against config {} ",request.getCaller(),handlerDeclaration);
|
||||||
|
if(!canInvokeStep(request.getStep(),request.getCaller(), handlerDeclaration))
|
||||||
|
throw new InsufficientPrivileges("User is not allowed to invoke "+request.getStep());
|
||||||
|
|
||||||
|
StepExecutionReport report=new StepExecutionReport(request);
|
||||||
|
LifecycleInformation info=report.getToSetLifecycleInformation();
|
||||||
|
report.setStatus(Report.Status.OK);
|
||||||
|
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||||
|
info.setLastInvokedStep(request.getStep());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return registeredSteps.get(request.getStep())
|
GuardedStepExecution exec=registeredSteps.get(request.getStep());
|
||||||
.setTheReport(report).execute();
|
exec.setTheReport(report);
|
||||||
|
exec.setHandlerConfiguration(handlerDeclaration);
|
||||||
|
log.debug("Actually executing Step with {} ",exec);
|
||||||
|
return exec.execute();
|
||||||
}catch (StepException | InvalidPluginRequestException e){
|
}catch (StepException | InvalidPluginRequestException e){
|
||||||
throw e;
|
throw e;
|
||||||
}catch (Throwable t) {
|
}catch (Throwable t) {
|
||||||
|
|
|
@ -33,7 +33,10 @@ public class RoleManager {
|
||||||
public boolean canInvokeStep(String stepID,User u) throws ConfigurationException {
|
public boolean canInvokeStep(String stepID,User u) throws ConfigurationException {
|
||||||
if(!accessMap.containsKey(stepID)) throw new ConfigurationException("Missing step "+stepID+" access definition");
|
if(!accessMap.containsKey(stepID)) throw new ConfigurationException("Missing step "+stepID+" access definition");
|
||||||
|
|
||||||
for (String role : accessMap.get(stepID).getRoles())
|
List<String> roles=accessMap.get(stepID).getRoles();
|
||||||
|
if(roles.isEmpty()) return true;
|
||||||
|
|
||||||
|
for (String role : roles)
|
||||||
if (u.getRoles().contains(role))
|
if (u.getRoles().contains(role))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,12 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
|
||||||
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
info.setLastOperationStatus(LifecycleInformation.Status.OK);
|
||||||
if(toHandle instanceof IndexDocumentReport)
|
if(toHandle instanceof IndexDocumentReport)
|
||||||
toUpdate.setToSetSpatialReference(((IndexDocumentReport)toHandle).getToSetSpatialReference());
|
toUpdate.setToSetSpatialReference(((IndexDocumentReport)toHandle).getToSetSpatialReference());
|
||||||
|
// Propagate changes for further processings
|
||||||
|
toUpdate.getTheRequest().getDocument().setTheDocument(toHandle.getResultingDocument());
|
||||||
|
toUpdate.setToSetLifecycleInformation(toHandle.getToSetLifecycleInformation());
|
||||||
|
|
||||||
|
// if(toHandle instanceof MaterializationReport)
|
||||||
|
// toUpdate.setToSetSpatialReference(((IndexDocumentReport)toHandle).getToSetSpatialReference());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ERROR : {
|
case ERROR : {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.plugins.faults.EventException;
|
import org.gcube.application.cms.plugins.faults.EventException;
|
||||||
|
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||||
import org.gcube.application.cms.plugins.faults.StepException;
|
import org.gcube.application.cms.plugins.faults.StepException;
|
||||||
import org.gcube.application.geoportal.common.faults.StorageException;
|
import org.gcube.application.geoportal.common.faults.StorageException;
|
||||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||||
|
@ -37,7 +38,7 @@ public interface MongoManagerI<T> {
|
||||||
public Iterable<Document> query(QueryRequest request) throws InvalidUserRoleException;
|
public Iterable<Document> query(QueryRequest request) throws InvalidUserRoleException;
|
||||||
public Iterable<T> filter(QueryRequest request) throws InvalidUserRoleException;
|
public Iterable<T> filter(QueryRequest request) throws InvalidUserRoleException;
|
||||||
|
|
||||||
public T performStep(String id, String step, Document options) throws IOException, StepException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
|
public T performStep(String id, String step, Document options) throws IOException, StepException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess, ConfigurationException, InsufficientPrivileges;
|
||||||
|
|
||||||
public T registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
|
public T registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
|
||||||
public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
|
public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.gcube.application.cms.plugins.LifecycleManager;
|
||||||
import org.gcube.application.cms.plugins.faults.EventException;
|
import org.gcube.application.cms.plugins.faults.EventException;
|
||||||
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||||
import org.gcube.application.cms.plugins.faults.StepException;
|
import org.gcube.application.cms.plugins.faults.StepException;
|
||||||
|
import org.gcube.application.cms.plugins.faults.UnrecognizedStepException;
|
||||||
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
import org.gcube.application.geoportal.common.model.plugins.LifecycleManagerDescriptor;
|
||||||
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
|
||||||
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
|
||||||
|
@ -417,8 +418,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Project performStep(String id, String step, Document options) throws StepException, JsonProcessingException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess {
|
public Project performStep(String id, String step, Document options) throws StepException, JsonProcessingException, ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess, ConfigurationException, InsufficientPrivileges {
|
||||||
Project document = lock(id,"Step "+step+" execution");
|
Project document = lock(id,"Step "+step+" execution");
|
||||||
|
Boolean store = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
User u = UserUtils.getCurrent().asInfo().getUser();
|
User u = UserUtils.getCurrent().asInfo().getUser();
|
||||||
|
@ -434,7 +437,15 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
document.getLifecycleInformation().cleanState();
|
document.getLifecycleInformation().cleanState();
|
||||||
document = step(document, step, options);
|
document = step(document, step, options);
|
||||||
}catch (InsufficientPrivileges | ConfigurationException e){
|
|
||||||
|
}catch (UnrecognizedStepException e){
|
||||||
|
store = false;
|
||||||
|
throw e;
|
||||||
|
}catch (ConfigurationException e){
|
||||||
|
store = false;
|
||||||
|
throw e;
|
||||||
|
}catch (InsufficientPrivileges e){
|
||||||
|
store = false;
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Throwable t){
|
} catch(Throwable t){
|
||||||
log.error("[UseCaseDescriptor {} ] ERROR Invoking Step {} on document {}" , useCaseDescriptor.getId(),step,id,t);
|
log.error("[UseCaseDescriptor {} ] ERROR Invoking Step {} on document {}" , useCaseDescriptor.getId(),step,id,t);
|
||||||
|
@ -445,13 +456,15 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
info.setLastInvokedStep(step);
|
info.setLastInvokedStep(step);
|
||||||
document.setLifecycleInformation(info);
|
document.setLifecycleInformation(info);
|
||||||
}finally{
|
}finally{
|
||||||
|
if (store) {
|
||||||
log.info("Storing {} [UseCaseDescriptor {}] After Step {}, Status : {} " ,id, useCaseDescriptor.getId(),
|
log.info("Storing {} [UseCaseDescriptor {}] After Step {}, Status : {} " ,id, useCaseDescriptor.getId(),
|
||||||
step,document.getLifecycleInformation().getLastOperationStatus());
|
step,document.getLifecycleInformation().getLastOperationStatus());
|
||||||
log.debug("LifecycleInformation is {} ",document.getLifecycleInformation());
|
log.debug("LifecycleInformation is {} ",document.getLifecycleInformation());
|
||||||
if(log.isTraceEnabled())log.trace("Document is {} ",Serialization.write(document));
|
if(log.isTraceEnabled())log.trace("Document is {} ",Serialization.write(document));
|
||||||
return unlockAndUpdate(document);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return unlockAndUpdate(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -684,13 +697,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Project step(Project theDocument, String step, Document callParameters) throws InsufficientPrivileges, ConfigurationException {
|
private Project step(Project theDocument, String step, Document callParameters) throws InsufficientPrivileges, ConfigurationException, StepException {
|
||||||
try {
|
try {
|
||||||
log.info("[UseCaseDescriptor {}] Invoking Step {} on {}", useCaseDescriptor.getId(), step, getManager().getDescriptor());
|
log.info("[UseCaseDescriptor {}] Invoking Step {} on {}", useCaseDescriptor.getId(), step, getManager().getDescriptor());
|
||||||
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
||||||
|
|
||||||
|
|
||||||
StepExecutionRequest request = new StepExecutionRequest(useCaseDescriptor, user.getUser(), user.getContext(), theDocument, step);
|
StepExecutionRequest request = new StepExecutionRequest(useCaseDescriptor, user.getUser(), user.getContext(), theDocument, step);
|
||||||
|
request.setCallParameters(callParameters);
|
||||||
|
|
||||||
log.debug("Requesting Step Execution {}", request);
|
log.debug("Requesting Step Execution {}", request);
|
||||||
StepExecutionReport report = getManager().performStep(request);
|
StepExecutionReport report = getManager().performStep(request);
|
||||||
|
@ -718,7 +732,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return report.prepareResult();
|
return report.prepareResult();
|
||||||
}catch (InsufficientPrivileges | ConfigurationException e){
|
}catch (InsufficientPrivileges | ConfigurationException | UnrecognizedStepException e){
|
||||||
throw e;
|
throw e;
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
log.error("Unable to perform step "+step,t);
|
log.error("Unable to perform step "+step,t);
|
||||||
|
|
|
@ -2,8 +2,11 @@ package org.gcube.application.geoportal.service.rest;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||||
|
import org.gcube.application.cms.plugins.faults.UnrecognizedStepException;
|
||||||
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||||
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.InvalidLockException;
|
import org.gcube.application.geoportal.service.model.internal.faults.InvalidLockException;
|
||||||
|
import org.gcube.application.geoportal.service.model.internal.faults.InvalidUserRoleException;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.ProjectLockedException;
|
import org.gcube.application.geoportal.service.model.internal.faults.ProjectLockedException;
|
||||||
import org.gcube.application.geoportal.service.model.internal.faults.ProjectNotFoundException;
|
import org.gcube.application.geoportal.service.model.internal.faults.ProjectNotFoundException;
|
||||||
|
|
||||||
|
@ -36,16 +39,26 @@ public abstract class GuardedMethod<T> {
|
||||||
log.trace("Executing actual method..");
|
log.trace("Executing actual method..");
|
||||||
result = run();
|
result = run();
|
||||||
return this;
|
return this;
|
||||||
|
}catch (InvalidUserRoleException e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
|
throw new WebApplicationException("Invalid Step ID ", e,Status.FORBIDDEN);
|
||||||
|
}catch (UnrecognizedStepException e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
|
throw new WebApplicationException("Invalid Step ID ", e,Status.BAD_REQUEST);
|
||||||
}catch (ConfigurationException e){
|
}catch (ConfigurationException e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED);
|
throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED);
|
||||||
}catch (InsufficientPrivileges e){
|
}catch (InsufficientPrivileges e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN);
|
throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN);
|
||||||
}catch(WebApplicationException e) {
|
}catch(WebApplicationException e) {
|
||||||
log.error("Throwing Web Application Exception ", e);
|
log.error("Throwing Web Application Exception ", e);
|
||||||
throw e;
|
throw e;
|
||||||
}catch(ProjectNotFoundException e){
|
}catch(ProjectNotFoundException e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
throw new WebApplicationException("Project not found", e,Status.NOT_FOUND);
|
throw new WebApplicationException("Project not found", e,Status.NOT_FOUND);
|
||||||
}catch(ProjectLockedException e){
|
}catch(ProjectLockedException e){
|
||||||
|
log.error("Returning exception ",e);
|
||||||
throw new WebApplicationException("Project is currently locked", e,Status.PRECONDITION_FAILED);
|
throw new WebApplicationException("Project is currently locked", e,Status.PRECONDITION_FAILED);
|
||||||
}catch(InvalidLockException e){
|
}catch(InvalidLockException e){
|
||||||
log.error("Lock exception ",e);
|
log.error("Lock exception ",e);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
|
||||||
|
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.gcube.application.cms.plugins.faults.EventException;
|
import org.gcube.application.cms.plugins.faults.EventException;
|
||||||
|
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
|
||||||
import org.gcube.application.cms.plugins.faults.StepException;
|
import org.gcube.application.cms.plugins.faults.StepException;
|
||||||
import org.gcube.application.cms.tests.TokenSetter;
|
import org.gcube.application.cms.tests.TokenSetter;
|
||||||
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
|
||||||
|
@ -88,7 +89,7 @@ public class LockTests extends BasicServiceTestUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnlock() throws StepException, EventException, IOException, ProjectNotFoundException, ProjectLockedException, InvalidLockException, DeletionException, ConfigurationException, StorageHubException, StorageException, InvalidUserRoleException, UnauthorizedAccess {
|
public void testUnlock() throws StepException, EventException, IOException, ProjectNotFoundException, ProjectLockedException, InvalidLockException, DeletionException, ConfigurationException, StorageHubException, StorageException, InvalidUserRoleException, UnauthorizedAccess, InsufficientPrivileges {
|
||||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||||
MongoManagerI<Project> managerInterface = manager;
|
MongoManagerI<Project> managerInterface = manager;
|
||||||
// create
|
// create
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected WebTarget baseTarget() {
|
protected WebTarget baseTarget() {
|
||||||
String testProfileId="profiledConcessioni";
|
String testProfileId="basic";
|
||||||
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
|
||||||
// invoke step Publish
|
// invoke step Publish
|
||||||
|
|
||||||
StepExecutionRequest approveDraftReq=new StepExecutionRequest();
|
StepExecutionRequest approveDraftReq=new StepExecutionRequest();
|
||||||
approveDraftReq.setStepID("APPROVE DRAFT");
|
approveDraftReq.setStepID("APPROVE-SUBMITTED");
|
||||||
doc=step(doc.getId(),approveDraftReq);
|
doc=step(doc.getId(),approveDraftReq);
|
||||||
System.out.println(doc);
|
System.out.println(doc);
|
||||||
assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
|
assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
|
||||||
|
|
Loading…
Reference in New Issue