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);
}
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));
}
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();
}
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;
}
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);
}
}
}
}
}
Aggregations