Skip to content

Commit

Permalink
Merge branch 'master' into rashik1144-patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
rsh1k authored Aug 23, 2024
2 parents c37b8a7 + c628743 commit d86e9a6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ public Response updateType(@PathParam("idOrVar") @Parameter(
contentTypeAPI, false);
final ImmutableMap.Builder<Object, Object> builderMap =
ImmutableMap.builder()
.putAll(contentTypeHelper.contentTypeToMap(
contentTypeAPI.find(tuple2._1.variable()), user))
.putAll(contentTypeHelper.contentTypeToMap(tuple2._1, user))
.put(MAP_KEY_WORKFLOWS,
this.workflowHelper.findSchemesByContentType(
contentType.id(), initData.getUser()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,13 @@ private Persona find(final String identifier, final User user, final boolean res
final Contentlet contentlet = APILocator.getContentletAPI().findContentletByIdentifier(identifier, live,
APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, respectFrontEndRoles);

return UtilMethods.isSet(contentlet) ? fromContentlet(contentlet) : null;

if(contentlet != null) {
return fromContentlet(contentlet);
}


return findPersonaByTag(identifier, user, respectFrontEndRoles).orElseGet(()->null);
}

@Override
Expand Down Expand Up @@ -502,11 +508,15 @@ public Structure getDefaultPersonaStructure() throws DotSecurityException, DotDa
public Optional<Persona> findPersonaByTag(final String personaTag, final User user, final boolean respectFrontEndRoles)
throws DotSecurityException, DotDataException {

if(UtilMethods.isEmpty(personaTag)){
return Optional.empty();
}

final StringBuilder query = new StringBuilder(" +baseType:").append(BaseContentType.PERSONA.getType())
.append(" +").append(PERSONA_KEY_TAG).append(":").append(personaTag);

final List<Contentlet> contentlets =
APILocator.getContentletAPI().search(query.toString(), -1, 0, StringPool.BLANK, user, respectFrontEndRoles);
APILocator.getContentletAPI().search(query.toString(), 1, 0, StringPool.BLANK, user, respectFrontEndRoles);
final Optional<Contentlet> persona = null != contentlets ? contentlets.stream().findFirst() : Optional.empty();
return persona.isPresent() ? Optional.ofNullable(fromContentlet(persona.get())) : Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import com.dotcms.repackage.org.apache.struts.Globals;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.UtilMethods;
import java.util.List;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.awaitility.Awaitility;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -289,6 +292,45 @@ public void testgetPersonasIncludingDefaultPersona_filterNewPersonaContentType_S
}
}
}




/**
* Method to test: {@link PersonaAPI#find(String identifier,com.liferay.portal.model.User user, boolean respectFrontendRoles)}
* When: finding a persona
* Should: the persona should be resolved by id or by keytag
*/
@Test
public void test_personas_test_resolve_by_keytag() throws Exception {

ContentType customPersonaType = new ContentTypeDataGen()
.host(host)
.baseContentType(BaseContentType.PERSONA).nextPersisted();

final Contentlet newPersona = new ContentletDataGen(customPersonaType.id())
.host(host)
.setProperty("name", "AnotherPersona" + System.currentTimeMillis())
.setProperty("keyTag", "AnotherPersona" + System.currentTimeMillis())
.nextPersisted();

Contentlet personaById = personaAPI.find(newPersona.getIdentifier(), APILocator.systemUser(), true);


assertTrue(UtilMethods.isSet(()->personaById.getIdentifier()));


Awaitility.await().atMost(15, TimeUnit.SECONDS).pollInterval(2, TimeUnit.SECONDS).until(() -> {
try {
Contentlet personaByKeyTag = personaAPI.find(newPersona.getStringProperty("keyTag"), APILocator.systemUser(), true);
assert(personaById.getIdentifier().equals(personaByKeyTag.getIdentifier()));
return true;
} catch (Exception e) {
// ignore
}
return false;
});

APILocator.getContentletAPI().destroy(newPersona, APILocator.systemUser(), false);


}
}

0 comments on commit d86e9a6

Please sign in to comment.