Search in sources :

Example 1 with BinaryAttachment

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())));
}
Also used : UpdateRepositoryParams(com.enonic.xp.repository.UpdateRepositoryParams) EditableRepository(com.enonic.xp.repository.EditableRepository) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test)

Example 2 with BinaryAttachment

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());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Instant(java.time.Instant) BinaryReference(com.enonic.xp.util.BinaryReference) LocalDate(java.time.LocalDate) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Date(java.util.Date) LocalDate(java.time.LocalDate) GeoPoint(com.enonic.xp.util.GeoPoint) Link(com.enonic.xp.util.Link)

Example 3 with BinaryAttachment

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());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Application(com.enonic.xp.app.Application) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Test(org.junit.jupiter.api.Test)

Example 4 with BinaryAttachment

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();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) ByteSource(com.google.common.io.ByteSource) ContentPath(com.enonic.xp.content.ContentPath) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ContentInheritType(com.enonic.xp.content.ContentInheritType)

Example 5 with BinaryAttachment

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);
    }
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) BinaryReference(com.enonic.xp.util.BinaryReference) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException)

Aggregations

BinaryAttachment (com.enonic.xp.node.BinaryAttachment)11 Test (org.junit.jupiter.api.Test)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 BinaryReference (com.enonic.xp.util.BinaryReference)4 ByteSource (com.google.common.io.ByteSource)4 UpdateRepositoryParams (com.enonic.xp.repository.UpdateRepositoryParams)3 AttachedBinaries (com.enonic.xp.node.AttachedBinaries)2 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)2 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 EditableRepository (com.enonic.xp.repository.EditableRepository)2 Repository (com.enonic.xp.repository.Repository)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2 Application (com.enonic.xp.app.Application)1 Branch (com.enonic.xp.branch.Branch)1 ContentInheritType (com.enonic.xp.content.ContentInheritType)1 ContentPath (com.enonic.xp.content.ContentPath)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 Property (com.enonic.xp.data.Property)1