use of com.enonic.xp.content.ContentInheritType 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.content.ContentInheritType in project xp by enonic.
the class ContentServiceImplTest_restore method restore_inherited.
@Test
public void restore_inherited() {
final Content content = createContent(ContentPath.ROOT, "content");
this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
refresh();
final ContentId importedId = archiveContext().callWith(() -> this.contentService.importContent(ImportContentParams.create().importContent(content).targetPath(content.getPath()).inherit(EnumSet.allOf(ContentInheritType.class)).build()).getContent().getId());
this.contentService.restore(RestoreContentParams.create().contentId(importedId).build());
final Set<ContentInheritType> inherit = this.contentService.getById(importedId).getInherit();
assertEquals(2, inherit.size());
assertTrue(inherit.contains(ContentInheritType.SORT));
assertTrue(inherit.contains(ContentInheritType.NAME));
}
use of com.enonic.xp.content.ContentInheritType in project xp by enonic.
the class ContentServiceImplTest_restore method restore_dont_stop_inherited.
@Test
public void restore_dont_stop_inherited() {
final Content content = createContent(ContentPath.ROOT, "content");
this.contentService.deleteWithoutFetch(DeleteContentParams.create().contentPath(content.getPath()).build());
refresh();
final ContentId importedId = archiveContext().callWith(() -> this.contentService.importContent(ImportContentParams.create().importContent(content).targetPath(content.getPath()).inherit(EnumSet.allOf(ContentInheritType.class)).build()).getContent().getId());
this.contentService.restore(RestoreContentParams.create().contentId(importedId).stopInherit(false).build());
final Set<ContentInheritType> inherit = this.contentService.getById(importedId).getInherit();
assertEquals(4, inherit.size());
}
use of com.enonic.xp.content.ContentInheritType in project xp by enonic.
the class ResetContentInheritanceCommand method execute.
void execute() {
final ProjectName sourceProjectName = fetchSourceProjectName(params.getProjectName());
validateSourceContentExist(sourceProjectName);
final Context targetContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(params.getProjectName().getRepoId()).branch(ContentConstants.BRANCH_DRAFT).authInfo(createAdminAuthInfo()).build();
targetContext.runWith(() -> {
if (contentService.contentExists(params.getContentId())) {
final Content targetContent = contentService.getById(params.getContentId());
final Set<ContentInheritType> typesToReset = params.getInherit().stream().filter(contentInheritType -> !targetContent.getInherit().contains(contentInheritType)).collect(Collectors.toSet());
if (!typesToReset.isEmpty()) {
final UpdateContentParams updateParams = new UpdateContentParams().contentId(targetContent.getId()).modifier(targetContent.getModifier()).stopInherit(false).editor(edit -> {
edit.inherit = processInherit(edit.inherit, typesToReset);
edit.workflowInfo = WorkflowInfo.inProgress();
});
contentService.update(updateParams);
syncContent(targetContent.getId(), sourceProjectName, params.getProjectName());
}
}
});
}
use of com.enonic.xp.content.ContentInheritType in project xp by enonic.
the class CreateContentCommandTest method mockContentNode.
private void mockContentNode(final String name, final String parentPath, final String language, final EnumSet<ContentInheritType> inherit) {
final PropertyTree data = new PropertyTree();
data.setSet(ContentPropertyNames.DATA, new PropertySet());
data.setString(ContentPropertyNames.CREATOR, "user:myidprovider:user1");
data.setString(ContentPropertyNames.TYPE, ContentTypeName.folder().toString());
data.setString(ContentPropertyNames.LANGUAGE, language);
data.addStrings(ContentPropertyNames.INHERIT, inherit.stream().map(ContentInheritType::name).collect(Collectors.toList()));
final Node contentNode = Node.create().id(NodeId.from("id1")).name(name).parentPath(NodePath.create(parentPath).build()).data(data).build();
Mockito.when(nodeService.getByPath(contentNode.path())).thenReturn(contentNode);
}
Aggregations