Search in sources :

Example 51 with PropertySet

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();
}
Also used : ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 52 with PropertySet

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);
}
Also used : FocalPoint(com.enonic.xp.image.FocalPoint) ValueType(com.enonic.xp.data.ValueType) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Property(com.enonic.xp.data.Property)

Example 53 with PropertySet

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);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 54 with PropertySet

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 55 with PropertySet

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);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PropertySet(com.enonic.xp.data.PropertySet)

Aggregations

PropertySet (com.enonic.xp.data.PropertySet)225 PropertyTree (com.enonic.xp.data.PropertyTree)150 Test (org.junit.jupiter.api.Test)69 Content (com.enonic.xp.content.Content)30 Node (com.enonic.xp.node.Node)20 CreateContentParams (com.enonic.xp.content.CreateContentParams)12 ContentId (com.enonic.xp.content.ContentId)11 Property (com.enonic.xp.data.Property)11 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)10 PrincipalKey (com.enonic.xp.security.PrincipalKey)9 ContentQuery (com.enonic.xp.content.ContentQuery)7 DescriptorKey (com.enonic.xp.page.DescriptorKey)7 ExtraDatas (com.enonic.xp.content.ExtraDatas)6 Form (com.enonic.xp.form.Form)6 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)6 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)5 ContentPropertyNames (com.enonic.xp.content.ContentPropertyNames)5 ExtraData (com.enonic.xp.content.ExtraData)5 PropertyPath (com.enonic.xp.data.PropertyPath)5 Page (com.enonic.xp.page.Page)5