Search in sources :

Example 6 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class ImageContentProcessorTest method testProcessCreateWithGeoData.

@Test
public void testProcessCreateWithGeoData() throws IOException {
    final XData gpsInfo = createXData(GPS_INFO_METADATA_NAME, "Gps Info", createGpsInfoMixinForm());
    Mockito.when(this.xDataService.getFromContentType(Mockito.any())).thenReturn(XDatas.from(gpsInfo));
    final CreateContentParams params = createContentParams(createAttachments());
    final ProcessCreateParams processCreateParams = new ProcessCreateParams(params, MediaInfo.create().addMetadata("geo lat", "1").addMetadata("geo long", "2").build());
    final GeoPoint geoPoint = new GeoPoint(1.0, 2.0);
    final ProcessCreateResult result = this.imageContentProcessor.processCreate(processCreateParams);
    final ExtraData geoExtraData = result.getCreateContentParams().getExtraDatas().first();
    assertEquals(geoExtraData.getName(), GPS_INFO_METADATA_NAME);
    assertEquals(geoExtraData.getData().getGeoPoint(MediaInfo.GPS_INFO_GEO_POINT, 0), geoPoint);
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) CreateContentParams(com.enonic.xp.content.CreateContentParams) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Example 7 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class ImageContentProcessorTest method testProcessUpdate.

@Test
public void testProcessUpdate() throws IOException {
    Mockito.when(contentService.getBinary(Mockito.any(), Mockito.any())).thenReturn(this.loadImage("cat-small.jpg"));
    final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().name(ContentTypeName.imageMedia()).superType(ContentTypeName.imageMedia()).build()).build();
    final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
    final PropertyTree data = new PropertyTree();
    data.addProperty(ContentPropertyNames.MEDIA, ValueFactory.newString("MyImage.jpg"));
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(ContentTypeName.imageMedia()).parentPath(ContentPath.ROOT).data(data).addExtraData(new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, new PropertyTree())).attachments(Attachments.from(Attachment.create().mimeType("image/jpg").name("MyImage.jpg").build())).build());
    result.getEditor().edit(editableContent);
    assertNotNull(editableContent.extraDatas.first().getData().getLong("pixelSize", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageHeight", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageWidth", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("byteSize", 0));
}
Also used : ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) ExtraData(com.enonic.xp.content.ExtraData) Test(org.junit.jupiter.api.Test)

Example 8 with ExtraData

use of com.enonic.xp.content.ExtraData in project xp by enonic.

the class PageRendererTest method createFragmentContent.

private Content createFragmentContent(final String id, final String name) {
    final PropertyTree metadata = new PropertyTree();
    metadata.setLong("myProperty", 1L);
    return Content.create().id(ContentId.from(id)).parentPath(ContentPath.ROOT).name(name).valid(true).createdTime(Instant.parse("2013-08-23T12:55:09.162Z")).creator(PrincipalKey.from("user:system:admin")).owner(PrincipalKey.from("user:myStore:me")).language(Locale.ENGLISH).displayName("My Content").modifiedTime(Instant.parse("2013-08-23T12:55:09.162Z")).modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.fragment()).addExtraData(new ExtraData(XDataName.from("myApplication:myField"), metadata)).build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ExtraData(com.enonic.xp.content.ExtraData)

Example 9 with ExtraData

use of com.enonic.xp.content.ExtraData 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 10 with ExtraData

use of com.enonic.xp.content.ExtraData 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)

Aggregations

ExtraData (com.enonic.xp.content.ExtraData)31 PropertyTree (com.enonic.xp.data.PropertyTree)18 Test (org.junit.jupiter.api.Test)10 XData (com.enonic.xp.schema.xdata.XData)8 XDataName (com.enonic.xp.schema.xdata.XDataName)8 Content (com.enonic.xp.content.Content)7 CreateContentParams (com.enonic.xp.content.CreateContentParams)5 ExtraDatas (com.enonic.xp.content.ExtraDatas)5 ApplicationKey (com.enonic.xp.app.ApplicationKey)4 Media (com.enonic.xp.content.Media)4 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)4 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)4 PropertySet (com.enonic.xp.data.PropertySet)4 Attachment (com.enonic.xp.attachment.Attachment)3 FormItem (com.enonic.xp.form.FormItem)3 Input (com.enonic.xp.form.Input)3 GeoPoint (com.enonic.xp.util.GeoPoint)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)2