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 11609 fixes mssql #13239

Merged
merged 42 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9525217
#11609 : Updating DB scripts. Adding upgrade task to create intermedi…
jcastro-dotcms Nov 6, 2017
f285dc8
#11609 added first draft for add/edit workflow action
Nov 8, 2017
8a6444a
#11609 merge done
Nov 8, 2017
ce25b42
#11609 almost code done for save/edit workflow actions associated to …
Nov 9, 2017
60ef0e7
#11609 the add action and action to step are done
Nov 15, 2017
eeb4172
#11609 Added the delete steps and dependencies/minor fixes for transa…
Nov 16, 2017
0929145
#11609 delete action from step done in the ui/ajax and endpoint
Nov 17, 2017
1f17c62
#11609 Added the deletes for the UI
Nov 20, 2017
4cd30de
#12960 changes for reorder done
Nov 28, 2017
fe70d6c
#13104 Added the new field requires lock options that supports locked…
Nov 29, 2017
677079c
#12960 added the scripts changes for all dbs
Nov 30, 2017
161c206
#12960 MERGE MASTER DONE
Nov 30, 2017
ab38919
#12960 added changes for the workflow, action and step new relationships
Dec 4, 2017
d30507c
#12960 merge done
Dec 4, 2017
4992dd9
#12960 notes and fixes
Dec 5, 2017
df465db
#12960 fixing the IT test
Dec 5, 2017
f558a7b
#12960 code review feedback
Dec 5, 2017
329da3e
#11691 added changes for the new endpoint for getting content type sc…
Dec 6, 2017
a0fbd9c
#12960 added changes for h2 and mysql
Dec 6, 2017
82e3837
#12960 added the changes for the show_on column
Dec 6, 2017
96c6ceb
#12960 adding changes for the showOn
Dec 6, 2017
6a709f4
#12960 merge done
Dec 7, 2017
c4d12df
#12960 changes for show on functionality
Dec 8, 2017
92347c1
resolving the error of the missing schemeid
Dec 8, 2017
5ab4a08
solving issue with content resource test
Dec 8, 2017
694375b
Fixing the Task04305UpdateWorkflowActionTable
Dec 11, 2017
62e4317
Reverting to master configuration
Dec 11, 2017
6caba12
#12960 merge done
Dec 11, 2017
43483c8
#12960 fixing postgres and oracle UT
Dec 12, 2017
cc1cde1
#11609 fixes for 11609
Dec 13, 2017
8f0b9bf
#11609 merge done
Dec 14, 2017
0261f20
#11609 configuration rollback
Dec 14, 2017
ff87ab2
#11609 fixes by code review
Dec 14, 2017
71bac80
#13208 now when there is a wrong workflow task associated to the step…
Dec 15, 2017
dd52111
#13208 merge master done
Dec 15, 2017
12c54fa
#11690 fixes for show_on
Dec 19, 2017
e2ee88e
Merge branch 'master' of github.com:dotCMS/core into issue-11609-fixe…
Dec 19, 2017
ad8f3cd
#11609 Fixes for the indexer that could not convert a short to boolea…
Dec 19, 2017
c834fab
#11609 rollback enterprise reference
Dec 19, 2017
058930d
#11609 removing unnecessary change
Dec 19, 2017
85dfe15
#11609 feedback changes
Dec 19, 2017
fa246ba
#11609 fixing the log level
Dec 19, 2017
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
2 changes: 1 addition & 1 deletion dotCMS/src/main/enterprise
14 changes: 14 additions & 0 deletions dotCMS/src/main/java/com/dotcms/util/ConversionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;

import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.util.UtilMethods;

/**
Expand Down Expand Up @@ -213,4 +214,17 @@ public static boolean toBoolean(final String strBool, final boolean defaultBool)
}
}

/**
* Based on a value get from the database, if it is a boolean will returns a cast.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Based on a value obtained from database, if it is a boolean will return a cast"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

* Otherwise will use the {@link DbConnectionFactory} to determinate the boolean value cross-db
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Otherwise, it will use .... to determine"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx

* @param objectBoolean {@link Object}
* @return boolean
*/
public static boolean toBooleanFromDb(final Object objectBoolean) {

return (objectBoolean instanceof Boolean)?
Boolean.class.cast(objectBoolean):
DbConnectionFactory.isDBTrue(objectBoolean.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
*/
public class WorkflowHelper {

private static final Set<WorkflowStatus> DEFAULT_SHOW_ON = EnumSet.of(WorkflowStatus.LOCKED, WorkflowStatus.UNLOCKED);

private final WorkflowAPI workflowAPI;
private final RoleAPI roleAPI;

Expand Down Expand Up @@ -472,7 +470,7 @@ public WorkflowAction save (final WorkflowActionForm workflowActionForm, final U
newAction.setCondition (workflowActionForm.getActionCondition());
newAction.setRequiresCheckout(workflowActionForm.isRequiresCheckout());
newAction.setShowOn((null != workflowActionForm.getShowOn() && !workflowActionForm.getShowOn().isEmpty())?
workflowActionForm.getShowOn():DEFAULT_SHOW_ON);
workflowActionForm.getShowOn():WorkflowAPI.DEFAULT_SHOW_ON);
newAction.setRoleHierarchyForAssign(workflowActionForm.isRoleHierarchyForAssign());

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotmarketing.portlets.templates.transform;

import com.dotcms.util.ConversionUtils;
import com.dotcms.util.transform.DBTransformer;
import com.dotmarketing.portlets.folders.model.Folder;
import java.util.ArrayList;
Expand Down Expand Up @@ -40,7 +41,7 @@ private static Folder transform(Map<String, Object> map) {
folder.setIDate((Date) map.get("idate"));
folder.setName((String) map.get("name"));
folder.setTitle((String) map.get("title"));
folder.setShowOnMenu((Boolean) map.getOrDefault("show_on_menu",false));
folder.setShowOnMenu(ConversionUtils.toBooleanFromDb(map.getOrDefault("show_on_menu",false)));
folder.setSortOrder((Integer) map.getOrDefault("sort_order",0));
folder.setFilesMasks((String) map.get("files_masks"));
folder.setIdentifier((String) map.get("identifier"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dotmarketing.portlets.workflows.business;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.dotcms.contenttype.model.type.ContentType;
import com.dotmarketing.beans.Permission;
Expand All @@ -14,20 +16,13 @@
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.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.WorkflowStep;
import com.dotmarketing.portlets.workflows.model.WorkflowTask;
import com.dotmarketing.portlets.workflows.model.*;
import com.liferay.portal.model.User;

public interface WorkflowAPI {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Move constants to a class or enum. rule


public static final Set<WorkflowStatus> DEFAULT_SHOW_ON = EnumSet.of(WorkflowStatus.LOCKED, WorkflowStatus.UNLOCKED);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Move "DEFAULT_SHOW_ON" to a class and lower its visibility rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is share between other object and need the visibility to be use as a part of the biz rule


public void registerBundleService ();

public WorkFlowActionlet newActionlet(String className) throws DotDataException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@
import com.dotmarketing.portlets.workflows.actionlet.UnarchiveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.UnpublishContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.WorkFlowActionlet;
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.WorkflowStep;
import com.dotmarketing.portlets.workflows.model.WorkflowTask;
import com.dotmarketing.portlets.workflows.model.*;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
Expand All @@ -61,16 +52,7 @@
import org.osgi.framework.BundleContext;

import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.*;

public class WorkflowAPIImpl implements WorkflowAPI, WorkflowAPIOsgiService {

Expand Down Expand Up @@ -631,6 +613,10 @@ public void saveAction(final WorkflowAction action,
}
}

private boolean isValidShowOn(final Set<WorkflowStatus> showOn) {
return null != showOn && !showOn.isEmpty();
}

private boolean existsScheme(final String schemeId) {

boolean existsScheme = false;
Expand Down Expand Up @@ -707,6 +693,12 @@ private void saveAction(final WorkflowAction action) throws DotDataException, Al
throw new DoesNotExistException("Workflow-does-not-exists-scheme");
}

if (!this.isValidShowOn(action.getShowOn())) {

Logger.info(this, "No show On data on workflow action record, bad data?");
action.setShowOn(WorkflowAPI.DEFAULT_SHOW_ON);
}

workFlowFactory.saveAction(action);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dotmarketing.portlets.workflows.model;

import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -31,16 +34,21 @@ public static String toCommaSeparatedString(final Set<WorkflowStatus> workflowSt
* @param value Object
* @return Set of {@link WorkflowStatus}
*/
public static Set<WorkflowStatus> toSet(Object value) {
public static Set<WorkflowStatus> toSet(final Object value) {

Set<WorkflowStatus> workflowStatusSet = Collections.emptySet();

if (null != value) {

workflowStatusSet = Stream
.<String>of(value.toString().split(DELIMITER))
.map(WorkflowStatus::valueOf)
.collect(Collectors.toSet());
if (null != value && UtilMethods.isSet(value.toString())) {

try {
workflowStatusSet = Stream
.<String>of(value.toString().split(DELIMITER))
.map(WorkflowStatus::valueOf)
.collect(Collectors.toSet());
} catch (Exception e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Either log or rethrow this exception. rule
MINOR Catch a list of specific exception subtypes instead. rule

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no specific one, so

Logger.error(WorkflowStatus.class, "No show On data on workflow action record, bad data?");
workflowStatusSet = Collections.emptySet();
}
}

return workflowStatusSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public void importWorkflowExport(File file) throws IOException {
wapi.saveStep(step);
}

for (WorkflowAction aciton : importer.getActions()) {
wapi.saveAction(aciton, null);
for (WorkflowAction action : importer.getActions()) {
wapi.saveAction(action, null);
}

for (WorkflowActionClass actionClass : importer.getActionClasses()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotmarketing.startup.runonce;

import com.dotcms.repackage.org.apache.commons.lang.StringUtils;
import com.dotcms.util.ConversionUtils;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.common.db.DotDatabaseMetaData;
import com.dotmarketing.common.db.ForeignKey;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class Task04305UpdateWorkflowActionTable implements StartupTask {

private static final String MYSQL_CREATE_INTERMEDIATE_TABLE = "CREATE TABLE workflow_action_step (action_id VARCHAR(36) NOT NULL, step_id VARCHAR(36) NOT NULL, action_order INT default 0)";
private static final String POSTGRES_CREATE_INTERMEDIATE_TABLE = MYSQL_CREATE_INTERMEDIATE_TABLE;
private static final String MSSQL_CREATE_INTERMEDIATE_TABLE = "CREATE TABLE workflow_action_step ( action_id NVARCHAR(36) NOT NULL, step_id NVARCHAR(36) NOT NULL action_order INT default 0, CONSTRAINT pk_workflow_action_step PRIMARY KEY NONCLUSTERED (action_id, step_id) )";
private static final String MSSQL_CREATE_INTERMEDIATE_TABLE = "CREATE TABLE workflow_action_step ( action_id NVARCHAR(36) NOT NULL, step_id NVARCHAR(36) NOT NULL, action_order INT default 0, CONSTRAINT pk_workflow_action_step PRIMARY KEY NONCLUSTERED (action_id, step_id) )";
private static final String ORACLE_CREATE_INTERMEDIATE_TABLE = "CREATE TABLE workflow_action_step ( action_id VARCHAR(36) NOT NULL, step_id VARCHAR(36) NOT NULL, action_order number(10,0) default 0, CONSTRAINT pk_workflow_action_step PRIMARY KEY (action_id, step_id) )";

private static final String MYSQL_CREATE_INTERMEDIATE_TABLE_PK = "ALTER TABLE workflow_action_step ADD CONSTRAINT pk_workflow_action_step PRIMARY KEY (action_id, step_id)";
Expand Down Expand Up @@ -392,16 +393,8 @@ private void closeAndStartTransaction() throws DotHibernateException {

private boolean isLocked(final Object requiresCheckout) {

boolean isLocked = false;

if (null != requiresCheckout) {

isLocked = (requiresCheckout instanceof Boolean)?
Boolean.class.cast(requiresCheckout):
DbConnectionFactory.isDBTrue(requiresCheckout.toString());
}

return isLocked;
return (null != requiresCheckout)?
ConversionUtils.toBooleanFromDb(requiresCheckout):false;
}

private String createIntermediateTableForeignKeyActionId() {
Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/resources/mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,7 @@ create table workflow_action(
);
create index workflow_idx_action_step on workflow_action(step_id);

CREATE TABLE workflow_action_step ( action_id NVARCHAR(36) NOT NULL, step_id NVARCHAR(36) NOT NULL action_order INT default 0, CONSTRAINT pk_workflow_action_step PRIMARY KEY NONCLUSTERED (action_id, step_id) );
CREATE TABLE workflow_action_step ( action_id NVARCHAR(36) NOT NULL, step_id NVARCHAR(36) NOT NULL, action_order INT default 0, CONSTRAINT pk_workflow_action_step PRIMARY KEY NONCLUSTERED (action_id, step_id) );
ALTER TABLE workflow_action_step ADD CONSTRAINT fk_workflow_action_step_action_id foreign key (action_id) references workflow_action(id);
ALTER TABLE workflow_action_step ADD CONSTRAINT fk_workflow_action_step_step_id foreign key (step_id) references workflow_step (id);

Expand Down