use of com.enonic.xp.content.ContentId in project xp by enonic.
the class AbstractDataSerializerTest method createImageComponent.
protected ImageComponent createImageComponent(final String imageId, final String imageDisplayName, final PropertyTree imageConfig) {
final ContentId id = ContentId.from(imageId);
final Content imageContent = Content.create().name("someimage").displayName(imageDisplayName).parentPath(ContentPath.ROOT).build();
Mockito.when(contentService.getById(id)).thenReturn(imageContent);
return ImageComponent.create().image(id).config(imageConfig).build();
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class TestDataFixtures method createFragmentComponent.
private static FragmentComponent createFragmentComponent(final String fragmentId, final String fragmentDisplayName) {
final ContentId id = ContentId.from(fragmentId);
final Content fragmentContent = Content.create().name("somefragment").displayName(fragmentDisplayName).parentPath(ContentPath.ROOT).build();
return FragmentComponent.create().fragment(id).build();
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class GetContentHandlerTest method getByIdInLayer.
@Test
public void getByIdInLayer() {
final Content content = TestDataFixtures.newExampleLayerContentBuilder().build();
final ContentId contentId = ContentId.from("mycontentId");
Mockito.when(this.contentService.getById(contentId)).thenReturn(content);
final ScriptValue result = runFunction("/test/GetContentHandlerTest.js", "getByIdInLayer");
Assert.assertEquals(2, result.getMember("inherit").getArray().size());
Assert.assertEquals("CONTENT", result.getMember("inherit").getArray().get(0).getValue());
Assert.assertEquals("NAME", result.getMember("inherit").getArray().get(1).getValue());
Assert.assertEquals("origin", result.getMember("originProject").getValue());
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class ContentDependenciesResolver method resolveOutboundDependenciesAggregation.
private Collection<ContentDependenciesAggregation> resolveOutboundDependenciesAggregation(final ContentId contentId) {
final Map<ContentTypeName, Long> aggregationJsonMap = new HashMap<>();
final Contents contents = this.contentService.getByIds(new GetContentByIdsParams(this.contentService.getOutboundDependencies(contentId)));
contents.forEach(existingContent -> {
final ContentTypeName contentTypeName = existingContent.getType();
final Long count = aggregationJsonMap.containsKey(contentTypeName) ? aggregationJsonMap.get(contentTypeName) + 1 : 1;
aggregationJsonMap.put(contentTypeName, count);
});
return aggregationJsonMap.entrySet().stream().map(entry -> new ContentDependenciesAggregation(entry.getKey(), entry.getValue())).collect(toList());
}
use of com.enonic.xp.content.ContentId in project xp by enonic.
the class ContentOutboundDependenciesIdsResolver method resolveOutboundDependenciesIds.
private ContentIds resolveOutboundDependenciesIds(final ContentId contentId) {
final Content content = this.contentService.getById(contentId);
final ContentIds.Builder contentIds = ContentIds.create();
final PropertySet contentPageData = new PropertyTree().getRoot();
if (content.getPage() != null) {
contentDataSerializer.toPageData(content.getPage(), contentPageData);
}
final Stream<Property> extraDataDependencies = content.hasExtraData() ? content.getAllExtraData().stream().flatMap(extraData -> extraData.getData().getProperties(ValueTypes.REFERENCE).stream()) : Stream.empty();
Stream.of(content.getData().getProperties(ValueTypes.REFERENCE).stream(), contentPageData.getProperties(ValueTypes.REFERENCE).stream(), extraDataDependencies).flatMap(s -> s).forEach(property -> {
final String value = property.getValue().toString();
if (!contentId.toString().equals(value) && !nullToEmpty(value).isBlank()) {
contentIds.add(ContentId.from(value));
}
});
if (content.getProcessedReferences() != null && content.getProcessedReferences().getSize() > 0) {
contentIds.addAll(content.getProcessedReferences());
}
return contentIds.build();
}
Aggregations