Search in sources :

Example 71 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ImageContentProcessor method updateImageMetadata.

private ExtraDatas updateImageMetadata(final EditableContent editable) {
    final Media media = (Media) editable.source;
    final Attachment mediaAttachment = media.getMediaAttachment();
    if (mediaAttachment == null) {
        return editable.extraDatas;
    }
    final ByteSource binary = contentService.getBinary(editable.source.getId(), mediaAttachment.getBinaryReference());
    if (binary == null) {
        return editable.extraDatas;
    }
    final BufferedImage image = toBufferedImage(binary);
    final Cropping cropping = media.getCropping();
    final long byteSize = mediaAttachment.getSize();
    final long imageWidth;
    final long imageHeight;
    final long imageSize;
    if (cropping == null || cropping.isUnmodified()) {
        imageWidth = image.getWidth();
        imageHeight = image.getHeight();
        imageSize = imageWidth * imageHeight;
    } else {
        final BufferedImage croppedImage = cropImage(image, cropping);
        imageWidth = croppedImage.getWidth();
        imageHeight = croppedImage.getHeight();
        imageSize = imageWidth * imageHeight;
    }
    ExtraData extraData = editable.extraDatas.getMetadata(MediaInfo.IMAGE_INFO_METADATA_NAME);
    if (extraData != null) {
        final PropertyTree xData = extraData.getData();
        setLongProperty(xData, IMAGE_INFO_PIXEL_SIZE, imageSize);
        setLongProperty(xData, IMAGE_INFO_IMAGE_HEIGHT, imageHeight);
        setLongProperty(xData, IMAGE_INFO_IMAGE_WIDTH, imageWidth);
        setLongProperty(xData, MEDIA_INFO_BYTE_SIZE, byteSize);
    }
    return editable.extraDatas;
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Media(com.enonic.xp.content.Media) ByteSource(com.google.common.io.ByteSource) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) Attachment(com.enonic.xp.attachment.Attachment) ExtraData(com.enonic.xp.content.ExtraData) BufferedImage(java.awt.image.BufferedImage) Cropping(com.enonic.xp.image.Cropping)

Example 72 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ImageContentProcessor method fillComputedFormItems.

private void fillComputedFormItems(Collection<ExtraData> extraDataList, MediaInfo mediaInfo, final CreateAttachment sourceAttachment) {
    for (ExtraData extraData : extraDataList) {
        final PropertyTree xData = extraData.getData();
        if (IMAGE_INFO.equals(extraData.getName().getLocalName())) {
            final Collection<String> tiffImageLengths = mediaInfo.getMetadata().get("tiffImagelength");
            final Collection<String> tiffImageWidths = mediaInfo.getMetadata().get("tiffImagewidth");
            if (tiffImageLengths.size() > 0 && tiffImageWidths.size() > 0) {
                final long tiffImageLength = Long.parseLong(tiffImageLengths.toArray()[0].toString());
                final long tiffImageWidth = Long.parseLong(tiffImageWidths.toArray()[0].toString());
                xData.setLong(IMAGE_INFO_PIXEL_SIZE, tiffImageLength * tiffImageWidth);
                xData.setLong(IMAGE_INFO_IMAGE_HEIGHT, tiffImageLength);
                xData.setLong(IMAGE_INFO_IMAGE_WIDTH, tiffImageWidth);
            }
            if (sourceAttachment != null) {
                try {
                    long mediaInfoByteSize = sourceAttachment.getByteSource().size();
                    xData.setLong(MEDIA_INFO_BYTE_SIZE, mediaInfoByteSize);
                } catch (IOException e) {
                    throw Exceptions.newRuntime("Failed to read BufferedImage from InputStream").withCause(e);
                }
            }
        }
    }
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ExtraData(com.enonic.xp.content.ExtraData) IOException(java.io.IOException)

Example 73 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class PageDefaultValuesProcessor method applyComponentDefaultValues.

private void applyComponentDefaultValues(final DescriptorBasedComponent cmp) {
    if (cmp.getDescriptor() == null) {
        return;
    }
    final Form cmpForm;
    if (cmp instanceof PartComponent) {
        final PartDescriptor partDescriptor = partDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = partDescriptor.getConfig();
    } else {
        final LayoutDescriptor layoutDescriptor = layoutDescriptorService.getByKey(cmp.getDescriptor());
        cmpForm = layoutDescriptor.getConfig();
    }
    if (cmpForm != null) {
        final PropertyTree cmpData = cmp.getConfig();
        formDefaultValuesProcessor.setDefaultValues(cmpForm, cmpData);
    }
}
Also used : LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Form(com.enonic.xp.form.Form) PartDescriptor(com.enonic.xp.region.PartDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) PartComponent(com.enonic.xp.region.PartComponent)

Example 74 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class ContentDataSerializer method toUpdateNodeData.

public PropertyTree toUpdateNodeData(final UpdateContentTranslatorParams params) {
    final PropertyTree newPropertyTree = new PropertyTree();
    final PropertySet contentAsData = newPropertyTree.getRoot();
    final Content content = params.getEditedContent();
    addMetadata(contentAsData, content, params.getModifier());
    contentAsData.addSet(DATA, content.getData().getRoot().copy(contentAsData.getTree()));
    if (content.hasExtraData()) {
        extraDataSerializer.toData(content.getAllExtraData(), contentAsData);
    }
    final Attachments attachments = mergeExistingAndUpdatedAttachments(content.getAttachments(), params);
    applyAttachmentsAsData(attachments, contentAsData);
    if (content.hasPage()) {
        pageDataSerializer.toData(content.getPage(), contentAsData);
    }
    addProcessedReferences(contentAsData, content.getProcessedReferences());
    return newPropertyTree;
}
Also used : Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Attachments(com.enonic.xp.attachment.Attachments)

Example 75 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FlattenedPageDataUpgraderTest method test.

private void test(final String oldJsonFile, final String newJsonFile) throws Exception {
    final JsonNode oldPageComponents = loadJson(oldJsonFile);
    final JsonNode newPageComponents = loadJson(newJsonFile);
    final PropertyTree oldData = new JsonToPropertyTreeTranslator().translate(oldPageComponents);
    final PropertyTree newData = new JsonToPropertyTreeTranslator().translate(newPageComponents);
    final HashMap<String, String> templateControllerMap = new HashMap<>();
    templateControllerMap.put("templateId", "com.enonic.app.features:main");
    FlattenedPageDataUpgrader.create().templateControllerMap(templateControllerMap).build().upgrade(oldData);
    // using string comparison because PropertyTree entries are same but might have different value type
    assertEquals(newData.toString(), oldData.toString());
}
Also used : JsonToPropertyTreeTranslator(com.enonic.xp.json.JsonToPropertyTreeTranslator) HashMap(java.util.HashMap) PropertyTree(com.enonic.xp.data.PropertyTree) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)660 Test (org.junit.jupiter.api.Test)405 PropertySet (com.enonic.xp.data.PropertySet)150 Content (com.enonic.xp.content.Content)126 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21