use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class Media method getCropping.
public Cropping getCropping() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return null;
}
final ValueType mediaPropertyType = mediaProperty.getType();
if (!mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
return null;
}
final PropertySet mediaData = getData().getSet(ContentPropertyNames.MEDIA);
final PropertySet croppingData = mediaData.getSet(ContentPropertyNames.MEDIA_CROPPING);
if (croppingData == null) {
return null;
}
final Double top = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_TOP);
final Double left = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_LEFT);
final Double bottom = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_BOTTOM);
final Double right = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_RIGHT);
final Double zoom = croppingData.getDouble(ContentPropertyNames.MEDIA_CROPPING_ZOOM);
if (left == null || top == null || bottom == null || right == null) {
return null;
}
// TODO The values stored in top, left, bottom and right are not the correct values
final double fixedTop = top / zoom;
final double fixedLeft = left / zoom;
final double fixedBottom = bottom / zoom;
final double fixedRight = right / zoom;
return Cropping.create().zoom(zoom).top(fixedTop).left(fixedLeft).bottom(fixedBottom).right(fixedRight).build();
}
use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class Media method getFocalPoint.
public FocalPoint getFocalPoint() {
final PropertyTree contentData = getData();
final Property mediaProperty = contentData.getProperty(ContentPropertyNames.MEDIA);
if (mediaProperty == null) {
return FocalPoint.DEFAULT;
}
final ValueType mediaPropertyType = mediaProperty.getType();
if (!mediaPropertyType.equals(ValueTypes.PROPERTY_SET)) {
return FocalPoint.DEFAULT;
}
final PropertySet mediaData = getData().getSet(ContentPropertyNames.MEDIA);
final PropertySet focalPointData = mediaData.getSet(ContentPropertyNames.MEDIA_FOCAL_POINT);
if (focalPointData == null) {
return FocalPoint.DEFAULT;
}
final Double focalX = focalPointData.getDouble(ContentPropertyNames.MEDIA_FOCAL_POINT_X);
final Double focalY = focalPointData.getDouble(ContentPropertyNames.MEDIA_FOCAL_POINT_Y);
if (focalX == null || focalY == null) {
return FocalPoint.DEFAULT;
}
return new FocalPoint(focalX, focalY);
}
use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class AuditLogSerializer method toCreateNodeParams.
public static CreateNodeParams.Builder toCreateNodeParams(final LogAuditLogParams auditLogParams) {
List<String> objectUris = auditLogParams.getObjectUris().stream().map(AuditLogUri::toString).collect(Collectors.toList());
final PropertyTree tree = new PropertyTree();
final PropertySet data = tree.getRoot();
data.addString(AuditLogPropertyNames.TYPE, auditLogParams.getType());
data.addInstant(AuditLogPropertyNames.TIME, auditLogParams.getTime());
data.addString(AuditLogPropertyNames.SOURCE, auditLogParams.getSource());
data.addString(AuditLogPropertyNames.USER, auditLogParams.getUser().toString());
data.addStrings(AuditLogPropertyNames.OBJECTURIS, objectUris);
data.addSet(AuditLogPropertyNames.DATA, auditLogParams.getData().getRoot().copy(data.getTree()));
return CreateNodeParams.create().nodeType(AuditLogConstants.NODE_TYPE).inheritPermissions(true).data(tree);
}
use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class CreateContentCommandTest method createTemplateFolderInsideSite.
@Test
public void createTemplateFolderInsideSite() {
final PropertyTree parentNodeData = new PropertyTree();
parentNodeData.setString(ContentPropertyNames.TYPE, ContentTypeName.site().toString());
parentNodeData.setSet(ContentPropertyNames.DATA, new PropertySet());
parentNodeData.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
final Node parentNode = Node.create().id(NodeId.from("id1")).name("parent").parentPath(ContentConstants.CONTENT_ROOT_PATH).data(parentNodeData).build();
Mockito.when(nodeService.getByPath(Mockito.eq(NodePath.create("/content/parent").build()))).thenReturn(parentNode);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.templateFolder()).name("_templates").parent(ContentPath.from("/parent")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build());
// exercise
final Content createdContent = command.execute();
assertNotNull(createdContent);
}
use of com.enonic.xp.data.PropertySet in project xp by enonic.
the class CreateContentCommandTest method mockContentRootNode.
private void mockContentRootNode(final String language) {
final PropertyTree tree = new PropertyTree();
tree.addString(ContentPropertyNames.TYPE, "folder");
tree.addString(ContentPropertyNames.CREATOR, "user:system:user1");
tree.addString(ContentPropertyNames.LANGUAGE, language);
tree.addSet(ContentPropertyNames.DATA, new PropertySet());
final Node contentRootNode = Node.create().id(NodeId.from("id1")).name("content").path("/content").parentPath(NodePath.ROOT).data(tree).build();
Mockito.when(nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH)).thenReturn(contentRootNode);
}
Aggregations