first implementation of the UnPublish step

This commit is contained in:
Francesco Mangiacrapa 2023-02-23 11:51:50 +01:00
parent 038bfe26ba
commit fa90d62eca
10 changed files with 115 additions and 36 deletions

View File

@ -1,9 +1,13 @@
# Changelog for org.gcube.application.cms.ckan-plugin
## [v1.1.0-SNAPSHOT] - 2023-02-23
- [#24570] Integrated the UnPublish operation
## [v1.0.1] - 2023-01-10
- Pom updates
- ## [v1.0.0] - 2022-02-24
## [v1.0.0] - 2022-02-24
- First release
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>default-lc-managers</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<name>gCube CMS - Default LC Managers</name>

View File

@ -1,12 +1,22 @@
package org.gcube.application.cms.plugins.implementations;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
import org.gcube.application.cms.implementations.ProjectAccess;
import org.gcube.application.cms.implementations.utils.UserUtils;
import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.PluginManagerInterface;
import org.gcube.application.cms.plugins.faults.*;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.InvalidProfileException;
import org.gcube.application.cms.plugins.faults.MaterializationException;
import org.gcube.application.cms.plugins.faults.ShutDownException;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.faults.UnrecognizedEventException;
import org.gcube.application.cms.plugins.faults.UnrecognizedStepException;
import org.gcube.application.cms.plugins.implementations.executions.GuardedEventManager;
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
@ -25,10 +35,9 @@ import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import org.gcube.application.geoportal.common.model.plugins.PluginDescriptor;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import java.util.HashMap;
import java.util.Map;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractLifeCycleManager extends AbstractPlugin implements LifecycleManager {

View File

@ -1,13 +1,13 @@
package org.gcube.application.cms.plugins.implementations;
import java.util.List;
import java.util.Map;
import org.gcube.application.cms.plugins.Plugin;
import org.gcube.application.cms.plugins.faults.InvalidProfileException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import java.util.List;
import java.util.Map;
public abstract class AbstractPlugin implements Plugin {

View File

@ -1,7 +1,7 @@
package org.gcube.application.cms.plugins.implementations;
import com.vdurmont.semver4j.Semver;
import lombok.extern.slf4j.Slf4j;
import java.util.Collections;
import org.bson.Document;
import org.gcube.application.cms.plugins.IndexerPluginInterface;
import org.gcube.application.cms.plugins.LifecycleManager;
@ -20,14 +20,16 @@ import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.utils.Files;
import java.util.Collections;
import com.vdurmont.semver4j.Semver;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Default3PhaseManager extends SimpleLifeCycleManager implements LifecycleManager {
protected static class Phases {
public static final String PENDING_APPROVAL="Pending Approval";
public static final String PUBLISHED="Published";
public static final String PUBLISHED=SimpleLifeCycleManager.Phases.PUBLISHED;
}
@ -92,6 +94,9 @@ public class Default3PhaseManager extends SimpleLifeCycleManager implements Life
return executeReject(theReport);
}
});
//Updated by Francesco
setStep(super.unPublishStep());
}
public Default3PhaseManager() {

View File

@ -1,16 +1,23 @@
package org.gcube.application.cms.plugins.implementations;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.document.accounting.User;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@ToString

View File

@ -1,6 +1,9 @@
package org.gcube.application.cms.plugins.implementations;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bson.Document;
import org.gcube.application.cms.plugins.IndexerPluginInterface;
import org.gcube.application.cms.plugins.LifecycleManager;
@ -10,7 +13,12 @@ import org.gcube.application.cms.plugins.faults.IndexingException;
import org.gcube.application.cms.plugins.faults.InvalidPluginRequestException;
import org.gcube.application.cms.plugins.faults.MaterializationException;
import org.gcube.application.cms.plugins.implementations.executions.GuardedStepExecution;
import org.gcube.application.cms.plugins.reports.*;
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.reports.IndexDocumentReport;
import org.gcube.application.cms.plugins.reports.MaterializationReport;
import org.gcube.application.cms.plugins.reports.Report;
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.requests.BaseExecutionRequest;
import org.gcube.application.cms.plugins.requests.BaseRequest;
import org.gcube.application.cms.plugins.requests.IndexDocumentRequest;
@ -28,9 +36,7 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDec
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.utils.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements LifecycleManager {
@ -42,13 +48,21 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
DESCRIPTOR.setId(PLUGIN_ID);
}
//Updated by Francesco
protected static class Phases {
public static final String PUBLISHED="Published";
public static final String UNPUBLISHED="UnPublished";
}
//Updated by Francesco
private static class Steps {
public static final OperationDescriptor PUBLISH = new OperationDescriptor("PUBLISH","Materialize & index project");
public static final OperationDescriptor UNPUBLISH = new OperationDescriptor("UNPUBLISH","UnPublish the project. DeMaterialize and DeIndex the project");
static{
PUBLISH.setAppliableToPhases(Collections.singletonList(LifecycleInformation.CommonPhases.DRAFT_PHASE));
UNPUBLISH.setAppliableToPhases(Collections.singletonList(Phases.PUBLISHED));
}
}
@ -112,11 +126,48 @@ public class SimpleLifeCycleManager extends AbstractLifeCycleManager implements
theReport = index(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
// setPhase
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
//TODO CHANGED THE SET PHASE ID
//theReport.getToSetLifecycleInformation().setPhase("PUBLISHED");
theReport.getToSetLifecycleInformation().setPhase(Phases.PUBLISHED);
}
return theReport;
}
});
setStep(unPublishStep());
}
//Updated by Francesco
protected GuardedStepExecution unPublishStep() {
return new GuardedStepExecution(Steps.UNPUBLISH) {
@Override
protected StepExecutionReport run() throws Exception {
//DeMaterialize
JSONPathWrapper wrapper = new JSONPathWrapper(theReport.getTheRequest().getDocument().getTheDocument().toJson());
for (String s : wrapper.getMatchingPaths("$..[?(@." + RegisteredFileSet.PAYLOADS + ")]")){
log.info("Requesting dematerialization for {} ",s);
for(MaterializationPlugin mat : getMaterializers(theReport.getTheRequest()))
theReport = deMaterialize(theReport,mat,new Document("fileSetPath",s));
if(!theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
break;
}
//DeIndex
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
for(IndexerPluginInterface indexer : getIndexers(theReport.getTheRequest())) {
log.info("Requesting deindexing for {} ",indexer.getDescriptor());
theReport = deIndex(theReport,indexer,getPublicIndexParams(theReport.getTheRequest()));
}
}
if(theReport.getToSetLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK))
theReport.getToSetLifecycleInformation().setPhase(LifecycleInformation.CommonPhases.DRAFT_PHASE);
return theReport;
}
};
}
protected void blockNonDraft(EventExecutionReport report) throws InvalidPluginRequestException {

View File

@ -1,11 +1,12 @@
package org.gcube.application.cms.plugins.implementations.executions;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class GuardedEventManager extends GuardedExecution<EventExecutionRequest,EventExecutionReport>{

View File

@ -1,9 +1,5 @@
package org.gcube.application.cms.plugins.implementations.executions;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.reports.DocumentHandlingReport;
@ -12,6 +8,11 @@ import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RequiredArgsConstructor

View File

@ -1,13 +1,14 @@
package org.gcube.application.cms.plugins.implementations.executions;
import org.gcube.application.cms.plugins.implementations.RoleManager;
import lombok.NonNull;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.cms.plugins.implementations.RoleManager;
import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.plugins.OperationDescriptor;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import lombok.NonNull;
public abstract class GuardedStepExecution extends GuardedExecution<StepExecutionRequest, StepExecutionReport>{