use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class RenameContentCommandTest method test_already_exists.
@Test
void test_already_exists() {
Node mockNode = Node.create().id(NodeId.from("testId")).build();
final RepositoryId repositoryId = RepositoryId.from("some.repo");
final Branch branch = Branch.from("somebranch");
when(nodeService.rename(isA(RenameNodeParams.class))).thenThrow(new NodeAlreadyExistAtPathException(NodePath.create("/content/mycontent2").build(), repositoryId, branch));
when(nodeService.getById(mockNode.id())).thenReturn(mockNode);
final Content content = createContent(true);
final RenameContentCommand command = createCommand(RenameContentParams.create().contentId(content.getId()).newName(ContentName.from("mycontent2")).build());
final ContentAlreadyExistsException exception = assertThrows(ContentAlreadyExistsException.class, command::execute);
assertEquals(branch, exception.getBranch());
assertEquals(repositoryId, exception.getRepositoryId());
}
use of com.enonic.xp.repository.RepositoryId 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.RepositoryId 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);
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class AbstractMetaDumpUpgrader method doUpgrade.
@Override
public void doUpgrade(final String dumpName) {
super.doUpgrade(dumpName);
final String timeMillis = Long.toString(System.currentTimeMillis());
FilePaths tmpFilePaths = new DefaultFilePaths() {
@Override
public PathRef branchMetaPath(final RepositoryId repositoryId, final Branch branch) {
return branchRootPath(repositoryId).resolve(branch.toString()).resolve("meta-" + timeMillis + ".tar.gz");
}
@Override
public PathRef versionMetaPath(final RepositoryId repositoryId) {
return branchRootPath(repositoryId).resolve("versions-" + timeMillis + ".tar.gz");
}
};
tmpDumpReader = FileDumpReader.create(null, basePath, dumpName, tmpFilePaths);
tmpDumpWriter = FileDumpWriter.create(basePath, dumpName, null, tmpFilePaths);
try {
dumpReader.getRepositories().forEach(this::upgradeRepository);
overwriteSourceFiles();
} catch (Exception e) {
try {
deleteBufferFiles();
} catch (Exception e2) {
LOG.error("Error while deleting buffer files", e);
}
throw new DumpUpgradeException("Error while upgrading dump [" + dumpName + "]", e);
} finally {
try {
tmpDumpReader.close();
tmpDumpWriter.close();
} catch (IOException e) {
LOG.error("Error while closing dump writer", e);
}
}
}
use of com.enonic.xp.repository.RepositoryId in project xp by enonic.
the class CommitDumpUpgrader method upgradeVersionEntry.
@Override
protected byte[] upgradeVersionEntry(final RepositoryId repositoryId, final String entryContent) {
final Pre6VersionsDumpEntryJson sourceEntry = deserializeValue(entryContent, Pre6VersionsDumpEntryJson.class);
final VersionsDumpEntryJson.Builder upgradedEntry = VersionsDumpEntryJson.create().nodeId(sourceEntry.getNodeId());
sourceEntry.getVersions().stream().map(version -> {
final boolean commit = commitedVersionIds.contains(version.getVersion());
return upgradeVersionDumpEntry(version, commit);
}).forEach(upgradedEntry::version);
return serialize(upgradedEntry.build());
}
Aggregations