Skip to content

Commit

Permalink
Issue 16820 default wfactions (#16833)
Browse files Browse the repository at this point in the history
* #16252 format source. Introduce format checker on build. Alter style … (#16288)

* #16252 format source. Introduce format checker on build. Alter style files

* #16252 remove unwanted file

* #16252 remove unwanted file

* Updating commit reference for src/main/enterprise

* try different location for checkstyle.xml

* Revert "#16252 format source. Introduce format checker on build. Alter style … (#16288)" (#16291)

This reverts commit 05f9082.

* Updating commit reference for src/main/enterprise

* #16809 first draft for the auto assign workflow delegate

* #16809 made some progress but not there yet

* #16809 now when uploading by webdav it is set to new step

* #16809 just a todos

* #16820 starting the upgrade task for the system actions to workflow actions mappin and auto assign workflow step listener too

* #16820 second part of the API (not 100% done yet) and starting the endpoints for system action mapping to workflow actions

* #16820 part of the code review feedback done

* #16820 rest endpoints done in order to save and get system action mappings

* #16820 latest changes for the Factory

* #16820 deletes a system action

* #16820 adding the search action by schemes id

* #16820 the fire default action is done on the workflow resource + multipart, missing more testing and unit test and the cases besides NEW+EDIT

* #16820 minor fix for findSystemActionsBySchemes

* #16820 starting the default action work on checkin

* #16820 adding fixes and endpoint to determine if an workflow action is being used as a default action

* #16820 now the action on the first step confirm to be deleted if the they are being referred by some content type

* #16820 now the content type may save system actions

* #16820 now the delete action warns when it is on the first step, the references to it, are being removed and addition the first step can not be deleted nor reordered

* #16820 now when get the content type, also get the system action mappings

* #16820 now the save content type is supporting more than one system action mapping

* #16820 minor feedback codacy applied

* #16820 adding refactoring over the response to be indexed by system action name

* #16820 changing a bit the format

* #16820 fixing an issue on saving system action mapping, now supporting more than one on the save type

* #16820 now the create content type is also supporting the ability to add system action mappings

* #16820 minor refactor to rename the systemActionMap to systemActionMappings on the ContentTypeForm

* #16820 refactor some names in order to keep the semathic, added the cache for system action mapping in addition to the support to remove mappings from the update content type

* #16820 including the workflows and system action mappings to the content type

* #16820 logic added when a content type or scheme are deleted, the mapping and cache are removed. In addition the translate action let has the logic to run a workflow as part of the save taking in consideration heuristics for the selection of the action or not

* #16820 avoid to publish if the save default action has a publish actionlet

* Add actions labels

* #16820 now the import also used a smart default action

* #16820 when trying to associated a mapping to a host, bad request is throw

* #16820 now can map on a scheme, only actions that are part of the scheme, otherwise throw Bad Request

* #16820 adding unit test

* #16820 adding unit test for default actions on checkin

* #16820 adding more testing scenarios

* #16820 more unit test

* #16820 minor change over the unit test

* #16820 fixing translate actionlet test

* #16820 fixing unit test and doing refactoring requested

* #16820 adding recursive dependency as lazy

* #16820 unit test for find first step

* #16820 fixes and unit testing for system mappings

* #16820 adding unit test for mapping by system workflow

* #16820 unit test for system actions

* #16820 feedback done and fixes on the unit test

* #16820 adding and fixing unit test

* #16820 Unit test fixing and improvements

* #16820 part of the code review done

* #16820 adding actionlet convenient methods to the workflow action class
  • Loading branch information
jdotcms authored and jgambarios committed Aug 14, 2019
1 parent b0e1faa commit 09f8214
Show file tree
Hide file tree
Showing 74 changed files with 5,059 additions and 571 deletions.
Expand Up @@ -1382,7 +1382,7 @@ public void testSave_GivenFixedTrueAndHostDifferentThanSYSTEMHOST_HostShouldBeSY
final ContentType languageVariableType = contentTypeApi.find("Languagevariable");
final List<Field> fields = languageVariableType.fields();
final ContentType languageVariableTypeWithAnotherHost =
ContentTypeBuilder.builder(languageVariableType).host("ANY-OTHER-HOST").build();
ContentTypeBuilder.builder(languageVariableType).host("ANY-OTHER-HOST").fixed(true).build();
languageVariableTypeWithAnotherHost.constructWithFields(fields);

ContentType savedLanguagaVariableType = contentTypeApi
Expand Down
Expand Up @@ -70,6 +70,7 @@ public static void prepare () throws Exception {

DotConnect dc = new DotConnect();
String structsToDelete = "(select inode from structure where structure.velocity_var_name like 'velocityVarNameTesting%' )";
String contentsStructsToDelete = "(select identifier from contentlet c inner join structure s on c.structure_inode = s.inode where s.velocity_var_name like 'velocityVarNameTesting%')";

dc.setSQL("delete from field where structure_inode in " + structsToDelete);
dc.loadResult();
Expand All @@ -81,6 +82,22 @@ public static void prepare () throws Exception {
+ structsToDelete + ")");
dc.loadResult();

new DotConnect()
.setSQL("delete from workflow_comment where workflowtask_id in " + contentsStructsToDelete)
.loadResult();

new DotConnect()
.setSQL("delete from workflow_history where workflowtask_id in " + contentsStructsToDelete)
.loadResult();

new DotConnect()
.setSQL("delete from workflowtask_files where workflowtask_id in " + contentsStructsToDelete)
.loadResult();

dc.setSQL("delete from workflow_task where webasset in " + contentsStructsToDelete);
dc.loadResult();


dc.setSQL("delete from contentlet where structure_inode in " + structsToDelete);
dc.loadResult();

Expand Down
Expand Up @@ -308,9 +308,10 @@ public static void delete(Contentlet contentlet) {
*/
public static void remove(Contentlet contentlet) {
try{
APILocator.getWorkflowAPI().deleteWorkflowTaskByContentletIdAnyLanguage(contentlet.getIdentifier(), APILocator.systemUser());
archive(contentlet);
delete(contentlet);
} catch (DotContentletStateException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand Down
Expand Up @@ -18,8 +18,6 @@
import com.dotcms.util.IntegrationTestInitService;
import com.dotmarketing.beans.Host;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.languagesmanager.model.Language;
Expand Down Expand Up @@ -144,18 +142,21 @@ public static void prepare() throws Exception {
}

@AfterClass
public static void cleanUpData() throws DotSecurityException, DotDataException {
public static void cleanUpData() throws Exception {
ContentletAPI contentletAPI = APILocator.getContentletAPI();
User user = APILocator.systemUser();
if(keyValueContentlet != null){
APILocator.getWorkflowAPI().deleteWorkflowTaskByContentletIdAnyLanguage(keyValueContentlet.getIdentifier(), APILocator.systemUser());
contentletAPI.archive(keyValueContentlet,user, false);
contentletAPI.delete(keyValueContentlet,user, false);
}
if(keyValueContentlet1 != null){
if(keyValueContentlet1 != null) {
APILocator.getWorkflowAPI().deleteWorkflowTaskByContentletIdAnyLanguage(keyValueContentlet1.getIdentifier(), APILocator.systemUser());
contentletAPI.archive(keyValueContentlet1,user, false);
contentletAPI.delete(keyValueContentlet1,user, false);
}
if(keyValueContentlet2 != null){
APILocator.getWorkflowAPI().deleteWorkflowTaskByContentletIdAnyLanguage(keyValueContentlet2.getIdentifier(), APILocator.systemUser());
contentletAPI.archive(keyValueContentlet2,user, false);
contentletAPI.delete(keyValueContentlet2,user, false);
}
Expand Down
@@ -1,24 +1,7 @@
package com.dotcms.rest.api.v1.page;

import static com.dotcms.util.CollectionsUtils.list;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.dotcms.content.elasticsearch.business.ESSearchResults;
import com.dotcms.datagen.ContainerDataGen;
import com.dotcms.datagen.FolderDataGen;
import com.dotcms.datagen.HTMLPageDataGen;
import com.dotcms.datagen.SiteDataGen;
import com.dotcms.datagen.StructureDataGen;
import com.dotcms.datagen.TemplateDataGen;
import com.dotcms.datagen.*;
import com.dotcms.rest.*;
import com.dotcms.rest.api.v1.personalization.PersonalizationPersonaPageView;
import com.dotcms.util.IntegrationTestInitService;
Expand All @@ -27,8 +10,8 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.factories.MultiTreeAPI;
import com.dotmarketing.portlets.containers.model.Container;
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.folders.model.Folder;
Expand All @@ -39,20 +22,23 @@
import com.dotmarketing.portlets.htmlpageasset.business.render.page.PageView;
import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset;
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.personas.business.PersonaAPI;
import com.dotmarketing.portlets.personas.model.Persona;
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PaginatedArrayList;
import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.json.JSONException;
import com.liferay.portal.model.User;
import com.liferay.util.StringPool;
import io.vavr.Tuple;
import org.elasticsearch.action.search.SearchResponse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jvnet.hk2.internal.Collector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -61,6 +47,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static com.dotcms.util.CollectionsUtils.list;
Expand Down Expand Up @@ -154,32 +141,41 @@ public void init() throws DotSecurityException, DotDataException {
public void testGetPersonalizedPersonasOnPage()
throws Exception {

final Host host = APILocator.getHostAPI().findDefaultHost(APILocator.systemUser(), false);
final MultiTreeAPI multiTreeAPI = APILocator.getMultiTreeAPI();
final String htmlPage = UUIDGenerator.generateUuid();
final String container = UUIDGenerator.generateUuid();
final String content = UUIDGenerator.generateUuid();
final Persona persona = APILocator.getPersonaAPI().getPersonas
(APILocator.getHostAPI().findDefaultHost(APILocator.systemUser(), false), true, false,
APILocator.systemUser(), false).stream().findFirst().get();
final String personaTag = persona.getKeyTag();
final String personalization = Persona.DOT_PERSONA_PREFIX_SCHEME + StringPool.COLON + personaTag;

multiTreeAPI.saveMultiTree(new MultiTree(htmlPage, container, content, UUIDGenerator.generateUuid(), 1)); // dot:default
multiTreeAPI.saveMultiTree(new MultiTree(htmlPage, container, content, UUIDGenerator.generateUuid(), 2, personalization)); // dot:somepersona

when(request.getRequestURI()).thenReturn("/index");
final Response response = pageResource.getPersonalizedPersonasOnPage(request, new EmptyHttpResponse(),
null, 0, 10, "title", "ASC", null, htmlPage);

final ResponseEntityView entityView = (ResponseEntityView)response.getEntity();
assertNotNull(entityView);

final PaginatedArrayList<PersonalizationPersonaPageView> paginatedArrayList = (PaginatedArrayList)entityView.getEntity();
assertNotNull(paginatedArrayList);

assertTrue(paginatedArrayList.stream().anyMatch(personalizationPersonaPageView ->
personalizationPersonaPageView.getPersona().get(PersonaAPI.KEY_TAG_FIELD).equals(personaTag) &&
Boolean.TRUE.equals(personalizationPersonaPageView.getPersona().get("personalized"))));
final List<Contentlet> contentlets = APILocator.getContentletAPI().search
(new StringBuilder("+contentType:persona +live:true +deleted:false +working:true +conhost:" + host.getIdentifier()).toString(),
-1, 0, "title desc", APILocator.systemUser(), false);
final Optional<Contentlet> personaOpt = contentlets.stream().findFirst();
if (personaOpt.isPresent()) {
final Persona persona = APILocator.getPersonaAPI().fromContentlet(personaOpt.get());
final String personaTag = persona.getKeyTag();
final String personalization = Persona.DOT_PERSONA_PREFIX_SCHEME + StringPool.COLON + personaTag;

multiTreeAPI.saveMultiTree(new MultiTree(htmlPage, container, content, UUIDGenerator.generateUuid(), 1)); // dot:default
multiTreeAPI.saveMultiTree(new MultiTree(htmlPage, container, content, UUIDGenerator.generateUuid(), 2, personalization)); // dot:somepersona

when(request.getRequestURI()).thenReturn("/index");
final Response response = pageResource.getPersonalizedPersonasOnPage(request, new EmptyHttpResponse(),
null, 0, 10, "title", "ASC", host.getIdentifier(), htmlPage);

final ResponseEntityView entityView = (ResponseEntityView) response.getEntity();
assertNotNull(entityView);

final PaginatedArrayList<PersonalizationPersonaPageView> paginatedArrayList = (PaginatedArrayList) entityView.getEntity();
assertNotNull(paginatedArrayList);

Logger.info(this, "************ htmlPage: " + htmlPage + ", container: " + container + ", personaTag: " + personaTag);
Logger.info(this, "************ PaginatedArrayList: " + paginatedArrayList.stream()
.map(p -> Tuple.of(p.getPersona().get(PersonaAPI.KEY_TAG_FIELD), p.getPersona().get("personalized"))).collect(Collectors.toList()));

assertTrue(paginatedArrayList.stream().anyMatch(personalizationPersonaPageView ->
personalizationPersonaPageView.getPersona().get(PersonaAPI.KEY_TAG_FIELD).equals(personaTag) &&
Boolean.TRUE.equals(personalizationPersonaPageView.getPersona().get("personalized"))));
}
}

/**
Expand Down

0 comments on commit 09f8214

Please sign in to comment.