Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 16820 defaultaction fixes #17273

Merged
merged 3 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6237,9 +6237,13 @@ public Contentlet copyContentlet(Contentlet contentletToCopy, Host host, Folder
newContentlet.setStringProperty(Contentlet.CONTENTLET_ASSET_NAME_COPY, newIdentifierName);
}

final String temporalFolder =
APILocator.getFileAssetAPI().getRealAssetPathTmpBinary() + File.separator
+ UUIDGenerator.generateUuid();

List <Field> fields = FieldsCache.getFieldsByStructureInode(contentlet.getStructureInode());
File srcFile;
File destFile = new File(APILocator.getFileAssetAPI().getRealAssetPathTmpBinary() + File.separator + user.getUserId());
File destFile = new File(temporalFolder);
if (!destFile.exists())
destFile.mkdirs();

Expand All @@ -6255,7 +6259,7 @@ public Contentlet copyContentlet(Contentlet contentletToCopy, Host host, Folder
}else{
fieldValue=srcFile.getName();
}
destFile = new File(APILocator.getFileAssetAPI().getRealAssetPathTmpBinary() + File.separator + user.getUserId() + File.separator + fieldValue);
destFile = new File(temporalFolder + File.separator + fieldValue);
if (!destFile.exists())
destFile.createNewFile();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ public SystemActionWorkflowActionMapping mapSystemActionToWorkflowAction(
workflowAction, workflowScheme);
} else if (UtilMethods.isSet(workflowSystemActionForm.getContentTypeVariable())) {

final ContentType contentType = APILocator.getContentTypeAPI(user).find(workflowSystemActionForm.getContentTypeVariable());
final ContentType contentType = this.findContentType(workflowSystemActionForm.getContentTypeVariable(), user);
mapping = this.workflowAPI.mapSystemActionToWorkflowActionForContentType(workflowSystemActionForm.getSystemAction(),
workflowAction, contentType);
} else {
Expand All @@ -1391,13 +1391,24 @@ public SystemActionWorkflowActionMapping mapSystemActionToWorkflowAction(
}
} else {

throw new DoesNotExistException("The workflow id: " + workflowSystemActionForm.getActionId() + " does not exists");
throw new DoesNotExistException("The workflow action with the id: " + workflowSystemActionForm.getActionId() + " does not exists");
}


return mapping;
}

private ContentType findContentType (final String variable, final User user)
throws DotDataException, DotSecurityException {

try {
return APILocator.getContentTypeAPI(user)
.find(variable);
} catch (NotFoundInDbException e) {
throw new BadRequestException("The content type: " + variable + " does not exists");
}
}

/**
* Save a WorkflowActionForm returning the WorkflowAction created.
* A WorkflowActionForm can send a stepId in that case the Action will be associated to the Step in the same transaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,8 @@ public boolean moveFile ( String inode, String folder ) throws Exception {
if ( id != null && id.getAssetType().equals( "contentlet" ) ) {

//Getting the contentlet file
Contentlet contentlet = APILocator.getContentletAPI().find( inode, user, false );
final Contentlet contentlet = APILocator.getContentletAPI().find( inode, user, false );
contentlet.setBoolProperty(Contentlet.DISABLE_WORKFLOW, true); // on move we do not want to run a workflow
Folder srcFolder = APILocator.getFolderAPI().find(contentlet.getFolder(),user,false);

if(contentlet.getFolder().equals("SYSTEM_FOLDER")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void executeAction(final WorkflowProcessor processor,
//First verify if we are handling a HTML page
if (structureType == Structure.STRUCTURE_TYPE_HTMLPAGE) {

Logger.info(this, "HEY the structure type is a Page");
final HTMLPageAsset htmlPageAsset = APILocator.getHTMLPageAssetAPI().fromContentlet(contentlet);

//Get the un-publish content related to this HTMLPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@
import com.dotmarketing.portlets.fileassets.business.IFileAsset;
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.workflows.actionlet.WorkFlowActionlet;
import com.dotmarketing.portlets.workflows.model.*;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.portlets.workflows.model.SystemActionWorkflowActionMapping;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClass;
import com.dotmarketing.portlets.workflows.model.WorkflowActionClassParameter;
import com.dotmarketing.portlets.workflows.model.WorkflowComment;
import com.dotmarketing.portlets.workflows.model.WorkflowHistory;
import com.dotmarketing.portlets.workflows.model.WorkflowProcessor;
import com.dotmarketing.portlets.workflows.model.WorkflowScheme;
import com.dotmarketing.portlets.workflows.model.WorkflowSearcher;
import com.dotmarketing.portlets.workflows.model.WorkflowState;
import com.dotmarketing.portlets.workflows.model.WorkflowStep;
import com.dotmarketing.portlets.workflows.model.WorkflowTask;
import com.dotmarketing.portlets.workflows.model.WorkflowTimelineItem;
import com.liferay.portal.model.User;

import java.util.*;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Future;

/**
Expand All @@ -30,7 +44,14 @@
*/
public interface WorkflowAPI {

/**
* Id of the System Workflow
*/
public static final String SYSTEM_WORKFLOW_ID = WorkFlowFactory.SYSTEM_WORKFLOW_ID;

/**
* Default show on
*/
public static final Set<WorkflowState> DEFAULT_SHOW_ON = EnumSet.of(WorkflowState.LOCKED, WorkflowState.UNLOCKED);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,21 @@
import com.liferay.portal.language.LanguageUtil;
import com.liferay.portal.model.User;
import com.liferay.util.StringPool;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
Expand All @@ -144,8 +157,6 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import javax.rmi.CORBA.Util;

import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.lang3.concurrent.ConcurrentUtils;
import org.elasticsearch.search.query.QueryPhaseExecutionException;
Expand Down Expand Up @@ -584,13 +595,47 @@ public void saveSchemeIdsForContentType(final ContentType contentType,
if(schemesIds.isEmpty()){
contentTypeAPI.updateModDate(contentType);
}
} catch(DotDataException e) {

this.cleanInvalidDefaultActionForContentType(contentType, schemesIds);
} catch(DotDataException | DotSecurityException e) {

Logger.error(WorkflowAPIImpl.class, String.format("Error saving Schemas: %s for Content type %s",
String.join(",", schemesIds), contentType.inode()));
}
}

private void cleanInvalidDefaultActionForContentType(final ContentType contentType,
final Set<String> schemesIds) throws DotDataException, DotSecurityException {

if (UtilMethods.isSet(schemesIds)) {

final List<Map<String, Object>> mappings = this.workFlowFactory
.findSystemActionsByContentType(contentType);
if (UtilMethods.isSet(mappings)) {

for (final Map<String, Object> mappingRow : mappings) {

final SystemActionWorkflowActionMapping mapping =
this.toSystemActionWorkflowActionMapping(mappingRow, contentType, APILocator.systemUser());
if (UtilMethods.isSet(mapping) && UtilMethods.isSet(mapping.getWorkflowAction())) {

if (!schemesIds.contains(mapping.getWorkflowAction().getSchemeId())) {

Logger.info(this, "Removing invalid system default action: " + mapping.getWorkflowAction() +
" on content type: " + contentType.variable() + ", the scheme: " + mapping.getWorkflowAction().getSchemeId() +
" is not longer valid on the content type schemes: " + schemesIds);
this.workFlowFactory.deleteSystemAction(mapping);
}
}
}
}
} else {

// no scheme remove all content type default actions.
this.workFlowFactory.deleteSystemActionsByContentType(contentType.variable());
}
}


@CloseDBIfOpened
@Override
Expand Down Expand Up @@ -3562,6 +3607,21 @@ public SystemActionWorkflowActionMapping mapSystemActionToWorkflowActionForConte
DotPreconditions.checkArgument(null != workflowAction, "Workflow Action can not be null");
DotPreconditions.checkArgument(!Host.HOST_VELOCITY_VAR_NAME.equals(contentType.variable()), "The Content Type can not be a Host");

final List<WorkflowScheme> contentTypeSchemes = this.findSchemesForContentType(contentType);

if (UtilMethods.isSet(contentTypeSchemes)) {

if (contentTypeSchemes.stream().noneMatch(scheme -> scheme.getId().equals(workflowAction.getSchemeId()))) {
throw new IllegalArgumentException(
"The workflow action: " + workflowAction.getId() +
" does not belong to any of the content type schemes");
}
} else {

throw new IllegalArgumentException("The content type action: " + contentType.variable() +
" does not have any scheme associated");
}

Logger.info(this, "Mapping the systemAction: " + systemAction +
", workflowAction: " + workflowAction.getName() + " and contentType: " + contentType.variable());

Expand Down