use of com.enonic.xp.node.BinaryAttachment in project xp by enonic.
the class ModifyRepositoryHandlerTest method modifyScoped.
@Test
void modifyScoped() throws Exception {
runScript("/lib/xp/examples/repo/modifyScoped.js");
ArgumentCaptor<UpdateRepositoryParams> captor = ArgumentCaptor.forClass(UpdateRepositoryParams.class);
Mockito.verify(this.repositoryService, Mockito.times(1)).updateRepository(captor.capture());
final UpdateRepositoryParams capturedParams = captor.getValue();
final EditableRepository edited = new EditableRepository(MOCK_REPO);
capturedParams.getEditor().accept(edited);
assertEquals("toBeModified", edited.source.getData().getString("myScopedObject.myScopedString"), "Test is invalid");
assertEquals("modified", edited.data.getString("myScopedObject.myScopedString"));
assertEquals("toBeKeptValue", edited.data.getString("toBeKept"));
final BinaryAttachment attachment = edited.binaryAttachments.get(0);
assertEquals(BinaryReference.from("myFile"), attachment.getReference());
assertTrue(attachment.getByteSource().contentEquals(ByteSource.wrap("Hello World".getBytes())));
}
use of com.enonic.xp.node.BinaryAttachment in project xp by enonic.
the class ScriptValueTranslator method handleValue.
private void handleValue(final PropertySet parent, final String name, final Object value) {
if (value instanceof Instant) {
parent.addInstant(name, (Instant) value);
} else if (value instanceof GeoPoint) {
parent.addGeoPoint(name, (GeoPoint) value);
} else if (value instanceof Double) {
parent.addDouble(name, (Double) value);
} else if (value instanceof Float) {
parent.addDouble(name, ((Float) value).doubleValue());
} else if (value instanceof Integer) {
parent.addLong(name, ((Integer) value).longValue());
} else if (value instanceof Byte) {
parent.addLong(name, ((Byte) value).longValue());
} else if (value instanceof Long) {
parent.addLong(name, ((Long) value));
} else if (value instanceof Number) {
parent.addDouble(name, ((Number) value).doubleValue());
} else if (value instanceof Boolean) {
parent.addBoolean(name, (Boolean) value);
} else if (value instanceof LocalDateTime) {
parent.addLocalDateTime(name, (LocalDateTime) value);
} else if (value instanceof LocalDate) {
parent.addLocalDate(name, (LocalDate) value);
} else if (value instanceof LocalTime) {
parent.addLocalTime(name, (LocalTime) value);
} else if (value instanceof Date) {
parent.addInstant(name, ((Date) value).toInstant());
} else if (value instanceof Reference) {
parent.addReference(name, (Reference) value);
} else if (value instanceof BinaryReference) {
parent.addBinaryReference(name, (BinaryReference) value);
} else if (value instanceof Link) {
parent.addLink(name, (Link) value);
} else if (value instanceof BinaryAttachment) {
final BinaryAttachment binaryAttachment = (BinaryAttachment) value;
parent.addBinaryReference(name, binaryAttachment.getReference());
if (includeBinaryAttachments) {
this.binaryAttachmentsBuilder.add(new BinaryAttachment(binaryAttachment.getReference(), binaryAttachment.getByteSource()));
}
} else {
parent.addString(name, value.toString());
}
}
use of com.enonic.xp.node.BinaryAttachment in project xp by enonic.
the class ApplicationNodeTransformerTest method binary_reference_added.
@Test
public void binary_reference_added() throws Exception {
final Application app = Mockito.mock(Application.class);
Mockito.when(app.getKey()).thenReturn(ApplicationKey.from("myApp"));
Mockito.when(app.getVersion()).thenReturn(Version.valueOf("1.0.0"));
Mockito.when(app.getMaxSystemVersion()).thenReturn("1.0.0");
Mockito.when(app.getMinSystemVersion()).thenReturn("1.0.0.");
Mockito.when(app.getDisplayName()).thenReturn("displayName");
final ByteSource appSource = ByteSource.wrap(ByteStreams.toByteArray(newBundle("myBundle", true).build()));
final CreateNodeParams createNodeParams = ApplicationNodeTransformer.toCreateNodeParams(app, appSource);
final PropertyTree data = createNodeParams.getData();
final BinaryReference binaryReference = data.getBinaryReference(ApplicationNodeTransformer.APPLICATION_BINARY_REF);
assertNotNull(binaryReference);
final BinaryAttachment binaryAttachment = createNodeParams.getBinaryAttachments().get(binaryReference);
assertEquals(appSource, binaryAttachment.getByteSource());
}
use of com.enonic.xp.node.BinaryAttachment in project xp by enonic.
the class CreatedEventSyncCommand method createImportParams.
private ImportContentParams createImportParams(final ContentToSync content, final ContentPath parentPath, final InsertManualStrategy insertManualStrategy) {
final BinaryAttachments.Builder builder = BinaryAttachments.create();
content.getSourceContent().getAttachments().forEach(attachment -> {
final ByteSource binary = content.getSourceContext().callWith(() -> contentService.getBinary(content.getId(), attachment.getBinaryReference()));
builder.add(new BinaryAttachment(attachment.getBinaryReference(), binary));
});
final ContentPath targetPath = buildNewPath(parentPath, content.getSourceContent().getName());
final EnumSet<ContentInheritType> inheritTypes = content.getSourceContent().getName().toString().equals(targetPath.getName()) ? EnumSet.allOf(ContentInheritType.class) : EnumSet.complementOf(EnumSet.of(ContentInheritType.NAME));
return ImportContentParams.create().importContent(content.getSourceContent()).targetPath(targetPath).binaryAttachments(builder.build()).inherit(inheritTypes).originProject(ProjectName.from(content.getSourceContext().getRepositoryId())).importPermissionsOnCreate(false).dryRun(false).insertManualStrategy(insertManualStrategy).build();
}
use of com.enonic.xp.node.BinaryAttachment in project xp by enonic.
the class NodeImporter method addBinary.
private void addBinary(final VirtualFile nodeFile, final BinaryAttachments.Builder builder, final Property binaryRefProperty) {
final BinaryReference binaryReference = binaryRefProperty.getBinaryReference();
try {
final VirtualFile binary = exportReader.getBinarySource(nodeFile, binaryReference.toString());
builder.add(new BinaryAttachment(binaryReference, binary.getByteSource()));
result.addBinary(binary.getPath().getPath(), binaryReference);
} catch (Exception e) {
result.addError("Error processing binary, skip", e);
}
}
Aggregations