contentRelationships = new ContentletRelationships(toContentlet);
}
List<Relationship> rels = RelationshipFactory.getAllRelationshipsByStructure(fromContentlet.getStructure());
for (Relationship r : rels) {
if(RelationshipFactory.isSameStructureRelationship(r, fromContentlet.getStructure())) {
ContentletRelationshipRecords selectedRecords = null;
//First all relationships as parent
for(ContentletRelationshipRecords records : contentRelationships.getRelationshipsRecords()) {
if(records.getRelationship().getInode().equalsIgnoreCase(r.getInode()) && records.isHasParent()) {
selectedRecords = records;
break;
}
}
if (selectedRecords == null) {
selectedRecords = contentRelationships.new ContentletRelationshipRecords(r, true);
contentRelationships.getRelationshipsRecords().add(contentRelationships.new ContentletRelationshipRecords(r, true));
}
//Adding to the list all the records the user was not able to see becuase permissions forcing them into the relationship
List<Contentlet> cons = getRelatedContent(fromContentlet, r, true, APILocator.getUserAPI().getSystemUser(), true);
for (Contentlet contentlet : cons) {
if (!perAPI.doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_READ, user, false)) {
selectedRecords.getRecords().add(0, contentlet);
}
}
//Then all relationships as child
for(ContentletRelationshipRecords records : contentRelationships.getRelationshipsRecords()) {
if(records.getRelationship().getInode().equalsIgnoreCase(r.getInode()) && !records.isHasParent()) {
selectedRecords = records;
break;
}
}
if (selectedRecords == null) {
selectedRecords = contentRelationships.new ContentletRelationshipRecords(r, false);
contentRelationships.getRelationshipsRecords().add(contentRelationships.new ContentletRelationshipRecords(r, false));
}
//Adding to the list all the records the user was not able to see becuase permissions forcing them into the relationship
cons = getRelatedContent(fromContentlet, r, false, APILocator.getUserAPI().getSystemUser(), true);
for (Contentlet contentlet : cons) {
if (!perAPI.doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_READ, user, false)) {
selectedRecords.getRecords().add(0, contentlet);
}
}
} else {
ContentletRelationshipRecords selectedRecords = null;
//First all relationships as parent
for(ContentletRelationshipRecords records : contentRelationships.getRelationshipsRecords()) {
if(records.getRelationship().getInode().equalsIgnoreCase(r.getInode())) {
selectedRecords = records;
break;
}
}
boolean hasParent = RelationshipFactory.isParentOfTheRelationship(r, fromContentlet.getStructure());
if (selectedRecords == null) {
selectedRecords = contentRelationships.new ContentletRelationshipRecords(r, hasParent);
contentRelationships.getRelationshipsRecords().add(contentRelationships.new ContentletRelationshipRecords(r, hasParent));
}
//Adding to the list all the records the user was not able to see because permissions forcing them into the relationship
List<Contentlet> cons = getRelatedContent(fromContentlet, r, APILocator.getUserAPI().getSystemUser(), true);
for (Contentlet contentlet : cons) {
if (!perAPI.doesUserHavePermission(contentlet, PermissionAPI.PERMISSION_READ, user, false)) {
selectedRecords.getRecords().add(0, contentlet);
}
}
}
}
for (ContentletRelationshipRecords cr : contentRelationships.getRelationshipsRecords()) {