use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.
the class ModifyRepositoryHandler method execute.
public RepositoryMapper execute() {
final RepositoryId repositoryId = RepositoryId.from(id);
final UpdateRepositoryParams updateRepositoryParams = UpdateRepositoryParams.create().repositoryId(repositoryId).editor(this::editRepository).build();
return new RepositoryMapper(repositoryServiceSupplier.get().updateRepository(updateRepositoryParams));
}
use of com.enonic.xp.repository.UpdateRepositoryParams 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.repository.UpdateRepositoryParams in project xp by enonic.
the class ModifyRepositoryHandlerTest method modifyRemoveProperty.
@Test
void modifyRemoveProperty() {
runScript("/lib/xp/examples/repo/modifyRemoveProperty.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);
assertTrue(edited.source.getData().hasProperty("myScopedObject"), "Test is invalid");
assertFalse(edited.data.hasProperty("myScopedObject"));
}
use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.
the class ProjectServiceImpl method doModify.
private Project doModify(final ModifyProjectParams params) {
final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> modifyProjectData(params, editableRepository.data)).build();
final Repository updatedRepository = repositoryService.updateRepository(updateParams);
if (!ProjectConstants.DEFAULT_PROJECT_NAME.equals(params.getName())) {
UpdateProjectRoleNamesCommand.create().securityService(securityService).projectName(params.getName()).projectDisplayName(params.getDisplayName()).build().execute();
}
return Project.from(updatedRepository);
}
use of com.enonic.xp.repository.UpdateRepositoryParams in project xp by enonic.
the class ProjectServiceImpl method doModifyIcon.
private void doModifyIcon(final ModifyProjectIconParams params) {
final UpdateRepositoryParams updateParams = UpdateRepositoryParams.create().repositoryId(params.getName().getRepoId()).editor(editableRepository -> {
if (params.getIcon() != null) {
try {
editableRepository.binaryAttachments.add(createProjectIcon(params.getIcon(), params.getScaleWidth()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
final PropertySet projectData = editableRepository.data.getSet(ProjectConstants.PROJECT_DATA_SET_NAME);
setIconData(projectData, params.getIcon());
}).build();
repositoryService.updateRepository(updateParams);
}
Aggregations