Changeset 31285 for main/trunk/greenstone3/CollectionGroups.java
- Timestamp:
- 2017-01-13T03:46:43+13:00 (7 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/CollectionGroups.java
r31265 r31285 65 65 Document doc = XMLConverter.newDOM(); 66 66 UserContext userContext = new UserContext(request); 67 67 68 NodeList collList; 69 NodeList groupList; 70 int collIndex = 0; 71 int grpIndex = 0; 72 boolean hierarchy = true; 73 68 74 // Prepare basic response 69 75 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); 70 76 Element result_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 77 result.appendChild(result_collection_list); 78 Element result_group_list = doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 79 result.appendChild(result_group_list); 71 80 72 81 // Get param list from request … … 81 90 groupPath = paramGroup.getAttribute(GSXML.VALUE_ATT); 82 91 } 92 Element paramHierarchy = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.HIERARCHY_ELEM); 93 if (paramHierarchy != null){ 94 hierarchy = true; 95 } 83 96 } 84 97 //Remove leading, ending / and dupliclated / … … 88 101 Element mrCollectionList = getMRCollectionList(userContext); 89 102 if (mrCollectionList == null){ 90 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));91 103 return result; 92 104 } 93 105 //Get current groups and collections 94 Element groupContent = getCurrentContent(groupPath); 106 Element currentContent = getCurrentContent(groupPath); 107 if (currentContent != null){ 108 currentContent = (Element) doc.importNode(currentContent, true); 109 } 95 110 96 111 //Get ungrouped collection list 97 Element ungroupedCollections = getUngroupedCollections(mrCollectionList); 98 99 // If groupContent is empty return empty collection list 100 if (groupContent == null) { 101 // If config file is broken 102 if (hierarchy == null || groupDesc == null) { 103 //Get ungrouped collection list 104 result.appendChild(doc.importNode(ungroupedCollections, true)); 112 Element ungroupedCollectionsList = getUngroupedCollections(mrCollectionList); 113 114 if (currentContent != null){ 115 if (hierarchy){ 116 collList = currentContent.getElementsByTagName(GSXML.COLLECTION_ELEM); 117 groupList = currentContent.getElementsByTagName(GSXML.GROUP_ELEM); 105 118 } else { 106 //If config is ok, but in this group no any collection or group 107 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER)); 108 } 109 return result; 110 } 111 NodeList currentContent = groupContent.getChildNodes(); 112 if (currentContent != null && currentContent.getLength() > 0) { 113 // Create CollectionList element in response 114 Element result_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 115 result.appendChild(result_collection_list); 116 Element result_group_list = doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 117 result.appendChild(result_group_list); 118 // Iterate over collections from current view 119 // i represents current position in groupConfig.xml 120 int i; 121 for (i=0; i < currentContent.getLength(); i++) { 122 //logger.warn("NODE CuR Content" + GSXML.xmlNodeToString(currentContent.item(i))); 123 124 if (currentContent.item(i).getNodeName() == GSXML.COLLECTION_ELEM) { 125 126 Element collection = (Element) currentContent.item(i); 127 String collection_name = collection.getAttribute(GSXML.NAME_ATT); 128 // Check whether collection from current view exists in message router response 129 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name); 130 if (checkedCollection != null) { 131 //Set position value 132 checkedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i)); 133 // Add collection to response 134 result_collection_list.appendChild(doc.importNode(checkedCollection, true)); 119 collList = GSXML.getChildrenByTagName(currentContent, GSXML.COLLECTION_ELEM); 120 groupList = GSXML.getChildrenByTagName(currentContent, GSXML.GROUP_ELEM); 121 } 122 //Check collection list for existence 123 int collListLenght = collList.getLength(); 124 for (collIndex = 0; collIndex < collListLenght; collIndex++) { 125 Element currentCollection = (Element) collList.item(collIndex); 126 String collection_name = currentCollection.getAttribute(GSXML.NAME_ATT); 127 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name); 128 if (checkedCollection != null) { 129 //Set position value 130 if (!hierarchy){ 131 int position = GSXML.getNodeIndex(currentCollection); 132 checkedCollection.setAttribute(GSXML.POSITION_ATT, Integer.toString(position)); 135 133 } 136 137 //Iterate over groups in current view 138 } else if (currentContent.item(i).getNodeName() == GSXML.GROUP_ELEM) { 139 Element currentGroup = (Element) currentContent.item(i); 140 String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT); 141 //Get group description 142 Element group = getGroupDescription(currentGroupName); 134 // Add collection to response 135 result_collection_list.appendChild(doc.importNode(checkedCollection, true)); 136 } else { 137 //remove collection from currentContent 138 currentCollection.getParentNode().removeChild(currentCollection); 139 collIndex--; 140 collListLenght--; 141 } 142 } 143 //check group 144 int groupListLenght = groupList.getLength(); 145 for (grpIndex = 0; grpIndex < groupListLenght; grpIndex++) { 146 Element currentGroup = (Element) groupList.item(grpIndex); 147 String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT); 148 Element groupDescription = getGroupDescription(currentGroupName); 149 if (groupDescription != null) { 143 150 //Set position value 144 if ( group != null){145 group.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));146 result_group_list.appendChild(doc.importNode(group, true));151 if (!hierarchy){ 152 int position = GSXML.getNodeIndex(currentGroup); 153 groupDescription.setAttribute(GSXML.POSITION_ATT, Integer.toString(position)); 147 154 } 148 149 } 150 151 } 155 result_group_list.appendChild(doc.importNode(groupDescription, true)); 156 } else { 157 //remove group from currentContent 158 currentGroup.getParentNode().removeChild(currentGroup); 159 grpIndex--; 160 groupListLenght--; 161 } 162 } 163 logger.error("Group list lenght " + groupListLenght+ " result_group_list is " + GSXML.elementToString(result_group_list, true)); 164 165 } 152 166 //Add ungrouped collections if groupPath /+ or "" or null 153 167 if (groupPath.isEmpty()) { 154 168 155 156 169 //Add each ungrouped collection to the collection list in loop 157 NodeList ungroupedCollectionNodes = GSXML.getChildrenByTagName(ungroupedCollections , GSXML.COLLECTION_ATT);170 NodeList ungroupedCollectionNodes = GSXML.getChildrenByTagName(ungroupedCollectionsList, GSXML.COLLECTION_ATT); 158 171 if (ungroupedCollectionNodes != null) { 159 for (int j = 0; j < ungroupedCollectionNodes.getLength(); j++) { 160 //logger.warn("UNGROUPED COLL ELEM" + GSXML.xmlNodeToString(ungroupedCollections).intern()); 161 Element ungroupedCollection = (Element) doc.importNode(ungroupedCollectionNodes.item(j), true); 162 ungroupedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i++)); 172 for (int k = 0; k < ungroupedCollectionNodes.getLength(); k++) { 173 Element ungroupedCollection = (Element) doc.importNode(ungroupedCollectionNodes.item(k), true); 174 if (!hierarchy){ 175 ungroupedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(grpIndex + collIndex++)); 176 } 163 177 result_collection_list.appendChild(ungroupedCollection); 178 if (hierarchy){ 179 180 currentContent.appendChild(doc.importNode(ungroupedCollectionNodes.item(k), true)); 181 } 164 182 } 165 183 } 166 184 167 185 } else { 168 Element groupDescription = getPathInfo(groupPath); 169 if (groupContent != null){ 170 result.appendChild(doc.importNode(groupDescription, true)); 171 } 172 } 173 } 174 186 Element pathInfo = getPathInfo(groupPath); 187 if (currentContent != null){ 188 result.appendChild(doc.importNode(pathInfo, true)); 189 } 190 } 191 if (hierarchy){ 192 result.appendChild(currentContent); 193 } 194 logger.error("currentContent is " + GSXML.elementToString(currentContent, true)); 175 195 return result; 176 196 }
Note:
See TracChangeset
for help on using the changeset viewer.