Skip to content

Commit

Permalink
Fixing content resource test (#13200)
Browse files Browse the repository at this point in the history
* resolving the error of the missing schemeid

* solving issue with content resource test

* Fixing the Task04305UpdateWorkflowActionTable

* Reverting to master configuration

* reverts of configuration

* reverting enterprise to the last commit
  • Loading branch information
jdotcms authored and dsilvam committed Dec 11, 2017
1 parent 079114b commit 551482e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ public void workflowTask() throws Exception {
// Save as Draft Step1 -> Step1
WorkflowAction saveDraft=new WorkflowAction();
saveDraft.setId(UUIDGenerator.generateUuid());
saveDraft.setSchemeId(scheme.getId());
saveDraft.setName("Save as Draft");
saveDraft.setOrder(1);
saveDraft.setNextStep(step1.getId());
Expand All @@ -582,10 +583,12 @@ public void workflowTask() throws Exception {
saveDraft.getId(),
APILocator.getRoleAPI().loadCMSAnonymousRole().getId(),
PermissionAPI.PERMISSION_USE) }));
APILocator.getWorkflowAPI().saveAction(saveDraft.getId(), step1.getId(),user);

// Save as Draft Step1 -> Step1
// Save as Draft Step1 -> Step1
WorkflowAction escalate=new WorkflowAction();
escalate.setId(UUIDGenerator.generateUuid());
escalate.setSchemeId(scheme.getId());
escalate.setName("Save and Assign");
escalate.setOrder(2);
escalate.setNextStep(step1.getId());
Expand All @@ -601,10 +604,16 @@ public void workflowTask() throws Exception {
escalate.getId(),
APILocator.getRoleAPI().loadCMSAnonymousRole().getId(),
PermissionAPI.PERMISSION_USE) }));
APILocator.getWorkflowAPI().saveAction(escalate.getId(), step1.getId(),user);

//Set mandatory workflow default action
scheme.setEntryActionId(saveDraft.getId());
APILocator.getWorkflowAPI().saveScheme(scheme);

// Send for review Step1 -> Step2
WorkflowAction sendReview=new WorkflowAction();
sendReview.setId(UUIDGenerator.generateUuid());
sendReview.setSchemeId(scheme.getId());
sendReview.setName("Send for review");
sendReview.setOrder(3);
sendReview.setNextStep(step2.getId());
Expand All @@ -618,10 +627,12 @@ public void workflowTask() throws Exception {
sendReview.getId(),
APILocator.getRoleAPI().loadCMSAnonymousRole().getId(),
PermissionAPI.PERMISSION_USE) }));
APILocator.getWorkflowAPI().saveAction(sendReview.getId(), step1.getId(),user);

// reject Step2 -> Step1
WorkflowAction reject=new WorkflowAction();
reject.setId(UUIDGenerator.generateUuid());
reject.setSchemeId(scheme.getId());
reject.setName("Reject");
reject.setOrder(1);
reject.setNextStep(step1.getId());
Expand All @@ -635,10 +646,12 @@ public void workflowTask() throws Exception {
reject.getId(),
APILocator.getRoleAPI().loadCMSAnonymousRole().getId(),
PermissionAPI.PERMISSION_USE) }));
APILocator.getWorkflowAPI().saveAction(sendReview.getId(), step2.getId(),user);

// publish Step2 -> Step3
WorkflowAction publish=new WorkflowAction();
publish.setId(UUIDGenerator.generateUuid());
publish.setSchemeId(scheme.getId());
publish.setName("Publish");
publish.setOrder(2);
publish.setNextStep(step3.getId());
Expand All @@ -652,6 +665,8 @@ public void workflowTask() throws Exception {
publish.getId(),
APILocator.getRoleAPI().loadCMSAnonymousRole().getId(),
PermissionAPI.PERMISSION_USE) }));
APILocator.getWorkflowAPI().saveAction(publish.getId(), step2.getId(),user);

WorkflowActionClass publishlet=new WorkflowActionClass();
publishlet.setActionId(publish.getId());
publishlet.setClazz(com.dotmarketing.portlets.workflows.actionlet.PublishContentActionlet.class.getCanonicalName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.dotcms.repackage.org.apache.commons.lang.StringUtils;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.db.HibernateUtil;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotHibernateException;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.startup.StartupTask;
import com.dotmarketing.util.Logger;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -53,10 +55,10 @@ public class Task04305UpdateWorkflowActionTable implements StartupTask {
private static final String MSSQL_FIND_SCHEME_ID_COLUMN = "SELECT scheme_id FROM workflow_action";
private static final String ORACLE_FIND_SCHEME_ID_COLUMN = "SELECT scheme_id FROM workflow_action";

private static final String MYSQL_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id VARCHAR(36) NOT NULL";
private static final String MYSQL_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id VARCHAR(36)";
private static final String POSTGRES_ADD_SCHEME_ID_COLUMN = MYSQL_ADD_SCHEME_ID_COLUMN;
private static final String MSSQL_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id NVARCHAR(36) NOT NULL";
private static final String ORACLE_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id varchar2(36) NOT NULL";
private static final String MSSQL_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id NVARCHAR(36)";
private static final String ORACLE_ADD_SCHEME_ID_COLUMN = "ALTER TABLE workflow_action ADD scheme_id varchar2(36)";

private static final String MYSQL_ADD_REQUIRES_CHECKOUT_OPTION_COLUMN = "ALTER TABLE workflow_action ADD requires_checkout_option VARCHAR(16) default 'both'";
private static final String POSTGRES_ADD_REQUIRES_CHECKOUT_OPTION_COLUMN = "ALTER TABLE workflow_action ADD requires_checkout_option VARCHAR(16) default 'both'";
Expand Down Expand Up @@ -258,12 +260,16 @@ private void addSchemeIdColumn(final DotConnect dc) throws DotDataException {

Logger.info(this, "Column 'workflow_action.scheme_id' does not exists, creating it");
needToCreate = true;
// in some databases if an error is throw the transaction is not longer valid
this.closeAndStartTransaction();
}
if (needToCreate) {
try {
dc.executeStatement(addSchemeIdColumn());
} catch (SQLException e) {
throw new DotRuntimeException("The 'scheme_id' column could not be created.", e);
} finally {
this.closeCommitAndStartTransaction();
}
}
} // addSchemeIdColumn.
Expand All @@ -280,27 +286,44 @@ private void createWorkflowActionStepTable(final DotConnect dc) throws DotDataEx

Logger.info(this, "Table 'workflow_action_step' does not exists, creating it");
needToCreate = true;
// in some databases if an error is throw the transaction is not longer valid
this.closeAndStartTransaction();
}

if (needToCreate) {
try {
dc.executeStatement(createIntermediateTable());
dc.setSQL(createIntermediateTable()).loadResult();
// The SQL Server and Oracle table definition already include de PK creation
if (DbConnectionFactory.isMySql() || DbConnectionFactory.isPostgres()) {
dc.executeStatement(createIntermediateTablePk());
dc.setSQL(createIntermediateTablePk()).loadResult();
}

// adding the FK
Logger.info(this, "Creating the Workflow action step intermediate FKs.");
dc.executeStatement(this.createIntermediateTableForeignKeyActionId());
dc.executeStatement(this.createIntermediateTableForeignKeyStepId());
} catch (SQLException e) {
dc.setSQL(this.createIntermediateTableForeignKeyActionId()).loadResult();
dc.setSQL(this.createIntermediateTableForeignKeyStepId()).loadResult();
} catch (Exception e) {
throw new DotRuntimeException(
"The 'workflow_action_step' table could not be created.", e);
} finally {
this.closeCommitAndStartTransaction();
}
}
} // createWorkflowActionStepTable.

private void closeCommitAndStartTransaction() throws DotHibernateException {
if (DbConnectionFactory.inTransaction()) {
HibernateUtil.closeAndCommitTransaction();
HibernateUtil.startTransaction();
}
}

private void closeAndStartTransaction() throws DotHibernateException {

HibernateUtil.closeSessionSilently();
HibernateUtil.startTransaction();
}

private boolean isLocked(final Object requiresCheckout) {

boolean isLocked = false;
Expand Down

0 comments on commit 551482e

Please sign in to comment.