2

In the content manager, we can see publications blueprinting hierarchy. When we right-click on publication, select blueprinting -> blueprinting hierarchy, we can see publications by levels in the popup.

Is there a way to do this via CoreService? Or I need to read the list of publications, and then use information about their parents and build a tree by myself?

2

I think what you are looking for is a filter called Tridion.ContentManager.Data.ContentManagement.BluePrintNodesFilterData or Tridion.ContentManager.Data.ContentManagement.BluePrintParentsFilterData. You should be able to use one of these filters in combination with the GetSystemWideList function.

This filter allows you to set the "ForRepository" property, which should be the ID of a publication. With this filter, you should get all parent publications of this publication.

For all properties of this filter, take a look at the Core Service documentation (chm) file. You can download this file in the SDL documentation site (https://docs.sdl.com/LiveContent/content/en-US/SDL%20Web-v5/GUID-74C197CB-6F91-424E-9FE6-19E8544EBECF)

  • I try to use this filters, but as result I have publications sorted by tcm uri. – user2757 Sep 25 '18 at 9:54
  • I believe you can than loop through the results and us the parents property. Alternatively, check this question and the different answers. There are some other suggestions in there as well. tridion.stackexchange.com/questions/4988/… – Harald Hoffelinck Sep 25 '18 at 10:24
0

This code will be useful if anybody needs to get publications in blueprint order

public List<PublicationData> getPublicationsInBlueprintOrder(List<PublicationData> publications) {
    int size = publications.size();
    List<PublicationData> orderedPublications = new ArrayList<>(size);
    HashSet<String> addedUris = new HashSet<>(size);

    while(orderedPublications.size() < size) {

        List<PublicationData> lastAdded = new ArrayList<>();

        for (PublicationData p : publications) {
            if(isRoot(p) || allParentsFound(p, addedUris)) {
                orderedPublications.add(p);
                addedUris.add(p.getId());
            }
        }

        publications.removeAll(lastAdded);
        lastAdded.clear();
    }

    return orderedPublications;
}



private static boolean allParentsFound(PublicationData publication, HashSet<String> addedUris) {
    if(isRoot(publication)) {
        return true;
    }

    List<String> parentsUris = publication.getParents()
                                          .getLinkToRepositoryData()
                                          .stream()
                                          .map(Link::getIdRef)
                                          .collect(Collectors.toList());
    return addedUris.containsAll(parentsUris);
}

private static boolean isRoot(PublicationData publication) {
    return isNull(publication.getParents()) || publication.getParents().getLinkToRepositoryData().isEmpty();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.