Skip to content

Commit

Permalink
Issue 13174 create systemworkflow (#13447)
Browse files Browse the repository at this point in the history
* #13395 CopyContentlet done

* #Added the work to create the system workflow on UT

* #13174 fixing a log

* #13174 feedback fixes
  • Loading branch information
jdotcms authored and jgambarios committed Jan 31, 2018
1 parent 891f50e commit e9665bb
Show file tree
Hide file tree
Showing 11 changed files with 813 additions and 18 deletions.
5 changes: 3 additions & 2 deletions dotCMS/src/main/java/com/dotcms/rest/ErrorResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ private ErrorResponseHelper() {}
*/
public Response getErrorResponse(final Response.Status status,
final Locale locale,
final String messageKey) {
final String messageKey,
final Object... arguments) {

try {

return Response.status(status).entity
(new ResponseEntityView
(Arrays.asList(new ErrorEntity(messageKey,
LanguageUtil.get(locale,
messageKey))))).build();
messageKey, arguments))))).build();


} catch (LanguageException e1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public Response getErrorResponse(final HttpServletRequest request,
final Response.Status status,
final Locale locale,
final String userId,
final String messageKey) {
final String messageKey,
final Object... arguments) {

return ErrorResponseHelper.INSTANCE.getErrorResponse(status, locale, messageKey);
return ErrorResponseHelper.INSTANCE.getErrorResponse(status, locale, messageKey, arguments);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.portlets.workflows.model.WorkflowScheme;
import com.dotmarketing.portlets.workflows.model.WorkflowStep;
import com.dotmarketing.portlets.workflows.util.WorkflowImportExportUtil;
import com.dotmarketing.portlets.workflows.util.WorkflowSchemeImportExportObject;
import com.dotmarketing.util.Logger;
import com.google.common.annotations.Beta;
import com.liferay.portal.model.User;
import com.liferay.util.LocaleUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.IntStream;
Expand All @@ -38,9 +41,10 @@
public class WorkflowResource {

private final WorkflowHelper workflowHelper;
private final WebResource webResource;
private final WorkflowAPI workflowAPI;
private final ResponseUtil responseUtil;
private final WebResource webResource;
private final WorkflowAPI workflowAPI;
private final ResponseUtil responseUtil;
private final WorkflowImportExportUtil workflowImportExportUtil;


/**
Expand All @@ -50,19 +54,23 @@ public WorkflowResource() {
this(WorkflowHelper.getInstance(),
APILocator.getWorkflowAPI(),
ResponseUtil.INSTANCE,
WorkflowImportExportUtil.getInstance(),
new WebResource());
}

@VisibleForTesting
protected WorkflowResource(final WorkflowHelper workflowHelper,
final WorkflowAPI workflowAPI,
final ResponseUtil responseUtil,
final WorkflowImportExportUtil workflowImportExportUtil,
final WebResource webResource) {

this.workflowHelper = workflowHelper;
this.webResource = webResource;
this.responseUtil = responseUtil;
this.workflowAPI = workflowAPI;
this.workflowHelper = workflowHelper;
this.webResource = webResource;
this.responseUtil = responseUtil;
this.workflowAPI = workflowAPI;
this.workflowImportExportUtil = workflowImportExportUtil;

}

/**
Expand Down Expand Up @@ -628,6 +636,7 @@ public final Response deleteAction(@Context final HttpServletRequest request,
} // deleteAction

/**
* Todo: change the signature to be align with the rest implementation such as: reorderAction
* Change the order of the steps in a scheme
* @param request HttpServletRequest
* @param stepId String step id
Expand Down Expand Up @@ -717,4 +726,51 @@ public final Response reorderAction(@Context final HttpServletRequest request,
return response;
} // reorderAction


/**
* Returns a set of actions associated to the schemeId
* @param request HttpServletRequest
* @param schemeId String
* @return Response
*/
@GET
@Path("/schemes/{schemeId}/export")
@JSONP
@NoCache
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
public final Response exportScheme(@Context final HttpServletRequest request,
@PathParam("schemeId") final String schemeId) {

final InitDataObject initDataObject = this.webResource.init
(null, true, request, true, null);
Response response;
WorkflowSchemeImportExportObject exportObject;
WorkflowScheme scheme;
Locale locale;

try {

Logger.debug(this, "Exporting the workflow scheme: " + schemeId);
scheme = this.workflowAPI.findScheme(schemeId);
exportObject = this.workflowImportExportUtil.buildExportObject(Arrays.asList(scheme));
response = Response.ok(new ResponseEntityView(exportObject)).build(); // 200
} catch (DoesNotExistException e) {

Logger.error(this.getClass(),
"The Scheme does not exist, id: " + schemeId, e);
locale = LocaleUtil.getLocale(request);
response = this.responseUtil.getErrorResponse(request, Response.Status.NOT_FOUND,
locale, initDataObject.getUser().getUserId(), "Workflow-does-not-exists-scheme-id", schemeId);
} catch (Exception e) {

Logger.error(this.getClass(),
"Exception on findActionsByScheme, schemeId: " + schemeId +
", exception message: " + e.getMessage(), e);
response = (e.getCause() instanceof SecurityException)?
ExceptionMapperUtil.createResponse(e, Response.Status.UNAUTHORIZED) :
ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}

return response;
} // exportScheme.
} // E:O:F:WorkflowResource.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ public static String getJsonErrorAsString(String message){
* @param entity JSON as String.
* @return Response with Status 400 and Media Type JSON.
*/
public static Response createResponse(String entity, String message){
public static Response createResponse(final String entity, final String message){

//Return 4xx message to the client.
return createResponse(entity, message, Response.Status.BAD_REQUEST);
}

/**
* Creates an error response with a specific status.
* @param entity JSON as String.
* @return Response with Status 400 and Media Type JSON.
*/
public static Response createResponse(final String entity,
final String message,
final Response.Status status){

return Response
.status(Response.Status.BAD_REQUEST)
.status(status)
.entity(entity)
.header("error-message", message)
.type(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.dotmarketing.db.DbConnectionFactory;
import com.dotmarketing.db.HibernateUtil;
import com.dotmarketing.exception.AlreadyExistException;
import com.dotmarketing.exception.DoesNotExistException;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
Expand Down Expand Up @@ -610,8 +611,10 @@ public WorkflowScheme findScheme(String id) throws DotDataException {
db.addParam(id);
scheme = (WorkflowScheme) this.convertListToObjects(db.loadObjectResults(), WorkflowScheme.class).get(0);
cache.add(scheme);
} catch (final IndexOutOfBoundsException e) {
throw new DoesNotExistException(e.getMessage(), e);
} catch (final Exception e) {
throw new DotDataException(e.getMessage(),e);
throw new DotDataException(e.getMessage(), e);
}
}
return scheme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,17 @@ public void importWorkflowExport(final File file) throws IOException {
}

public WorkflowSchemeImportExportObject buildExportObject() throws DotDataException, DotSecurityException {

final WorkflowAPI workflowAPI = APILocator.getWorkflowAPI();
final List<WorkflowScheme> schemes = workflowAPI.findSchemes(true);

return buildExportObject(schemes);
}

public WorkflowSchemeImportExportObject buildExportObject(final List<WorkflowScheme> schemes)
throws DotDataException, DotSecurityException {

final WorkflowAPI workflowAPI = APILocator.getWorkflowAPI();
List<WorkflowScheme> schemes = workflowAPI.findSchemes(true);
List<WorkflowStep> steps = new ArrayList<WorkflowStep>();
List<WorkflowAction> actions = new ArrayList<WorkflowAction>();
List<WorkflowActionClass> actionClasses = new ArrayList<WorkflowActionClass>();
Expand All @@ -152,10 +161,10 @@ public WorkflowSchemeImportExportObject buildExportObject() throws DotDataExcept
// steps actions
this.exportStepActions(workflowAPI, actionStepsListMap, steps, scheme);
}

DotConnect dc = new DotConnect();
dc.setSQL("select id, scheme_id, structure_id from workflow_scheme_x_structure");
List<Map<String, String>> workflowStructures = dc.loadResults();
List<Map<String, String>> workflowStructures = dc.loadResults();

WorkflowSchemeImportExportObject export = new WorkflowSchemeImportExportObject();
export.setSchemes(schemes);
Expand All @@ -167,7 +176,6 @@ public WorkflowSchemeImportExportObject buildExportObject() throws DotDataExcept
export.setWorkflowStructures(workflowStructures);
export.setActionSteps(actionStepsListMap);
return export;

}

private void exportStepActions(final WorkflowAPI wapi,
Expand Down
Loading

0 comments on commit e9665bb

Please sign in to comment.