/** * Get the list of contents by relationship if exists. * * @param structure The content structure * @param contentlet The content * @param parametersOptions The macro form options parameters * @return Map<Relationship,List<Contentlet>> * @throws DotSecurityException */ private static Map<Relationship, List<Contentlet>> getRelationships( Structure structure, Contentlet contentlet, String parametersOptions, User user) throws DotDataException, DotSecurityException { LanguageAPI lAPI = APILocator.getLanguageAPI(); Map<Relationship, List<Contentlet>> contentRelationships = new HashMap<Relationship, List<Contentlet>>(); if (contentlet == null) return contentRelationships; List<Relationship> rels = RelationshipFactory.getAllRelationshipsByStructure(contentlet.getStructure()); for (Relationship rel : rels) { String[] opt = parametersOptions.split(";"); for (String text : opt) { if (text.indexOf(rel.getRelationTypeValue()) != -1) { String[] identArray = text.substring(text.indexOf("=") + 1) .replaceAll("\\[", "") .replaceAll("\\]", "") .split(","); List<Contentlet> cons = conAPI.findContentletsByIdentifiers( identArray, true, lAPI.getDefaultLanguage().getId(), user, true); if (cons.size() > 0) { contentRelationships.put(rel, cons); } } } } return contentRelationships; }
private List<Map<String, Object>> findChildFacilities( List<Contentlet> buildingConts, String filter, User user, boolean respectFrontendRoles) throws DotDataException, DotSecurityException { List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); // Searching for children facilities Structure facilityStructure = eventAPI.getFacilityStructure(); // Facility Structure might be absent http://jira.dotmarketing.net/browse/DOTCMS-6275 if (facilityStructure.getName() != null) { Field titleField = facilityStructure.getFieldVar("title"); String luceneQuery = "+structureInode:" + facilityStructure.getInode() + " +("; for (Contentlet cont : buildingConts) { luceneQuery += " Building-Facility:" + cont.getIdentifier() + " "; } luceneQuery += ") "; if (UtilMethods.isSet(filter)) luceneQuery += " +" + titleField.getFieldContentlet() + ":" + filter.trim() + "*"; List<Contentlet> matches = contAPI.search( luceneQuery, -1, 0, titleField.getFieldContentlet(), user, respectFrontendRoles); List<Relationship> rels = RelationshipFactory.getAllRelationshipsByStructure(eventAPI.getBuildingStructure()); for (Contentlet cont : matches) { List<Contentlet> relCont = new ArrayList<Contentlet>(); for (Relationship rel : rels) { if (rel.getChildStructure().equals(eventAPI.getFacilityStructure()) && rel.getParentStructure().equals(eventAPI.getBuildingStructure())) { relCont.addAll( APILocator.getContentletAPI() .getRelatedContent(cont, rel, user, respectFrontendRoles)); } } Map<String, Object> contMap = cont.getMap(); contMap.put("buildings", relCont); results.add(contMap); } } return results; }
private void _deleteStructure(ActionForm form, ActionRequest req, ActionResponse res) throws Exception { try { Structure structure = (Structure) req.getAttribute(WebKeys.Structure.STRUCTURE); User user = _getUser(req); HttpServletRequest httpReq = ((ActionRequestImpl) req).getHttpServletRequest(); // Checking permissions _checkDeletePermissions(structure, user, httpReq); // checking if there is containers using this structure List<Container> containers = APILocator.getContainerAPI().findContainersForStructure(structure.getInode()); if (containers.size() > 0) { StringBuilder names = new StringBuilder(); for (int i = 0; i < containers.size(); i++) names.append(containers.get(i).getFriendlyName()).append(", "); Logger.warn( EditStructureAction.class, "Structure " + structure.getName() + " can't be deleted because the following containers are using it: " + names); SessionMessages.add(req, "message", "message.structure.notdeletestructure.container"); return; } if (!structure.isDefaultStructure()) { @SuppressWarnings("rawtypes") List fields = FieldFactory.getFieldsByStructure(structure.getInode()); @SuppressWarnings("rawtypes") Iterator fieldsIter = fields.iterator(); while (fieldsIter.hasNext()) { Field field = (Field) fieldsIter.next(); FieldFactory.deleteField(field); } int limit = 200; int offset = 0; List<Contentlet> contentlets = conAPI.findByStructure(structure, user, false, limit, offset); int size = contentlets.size(); while (size > 0) { conAPI.delete(contentlets, user, false); contentlets = conAPI.findByStructure(structure, user, false, limit, offset); size = contentlets.size(); } if (structure.getStructureType() == Structure.STRUCTURE_TYPE_FORM) { @SuppressWarnings({"deprecation", "static-access"}) Structure st = StructureCache.getStructureByName(fAPI.FORM_WIDGET_STRUCTURE_NAME_FIELD_NAME); if (UtilMethods.isSet(st) && UtilMethods.isSet(st.getInode())) { @SuppressWarnings({"deprecation", "static-access"}) Field field = st.getField(fAPI.FORM_WIDGET_FORM_ID_FIELD_NAME); List<Contentlet> widgetresults = conAPI.search( "+structureInode:" + st.getInode() + " +" + field.getFieldContentlet() + ":" + structure.getInode(), 0, 0, "", user, false); if (widgetresults.size() > 0) { conAPI.delete(widgetresults, user, false); } } } // http://jira.dotmarketing.net/browse/DOTCMS-6435 if (structure.getStructureType() == Structure.STRUCTURE_TYPE_FILEASSET) { StructureFactory.updateFolderFileAssetReferences(structure); } List<Relationship> relationships = RelationshipFactory.getRelationshipsByParent(structure); for (Relationship rel : relationships) { RelationshipFactory.deleteRelationship(rel); } relationships = RelationshipFactory.getRelationshipsByChild(structure); for (Relationship rel : relationships) { RelationshipFactory.deleteRelationship(rel); } PermissionAPI perAPI = APILocator.getPermissionAPI(); perAPI.removePermissions(structure); StructureFactory.deleteStructure(structure); // Removing the structure from cache FieldsCache.removeFields(structure); StructureCache.removeStructure(structure); StructureServices.removeStructureFile(structure); SessionMessages.add(req, "message", "message.structure.deletestructure"); } else { SessionMessages.add(req, "message", "message.structure.notdeletestructure"); } } catch (Exception ex) { Logger.debug(EditStructureAction.class, ex.toString()); throw ex; } }