List of usage examples for org.apache.commons.collections.map ListOrderedMap containsKey
public boolean containsKey(Object key)
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.EntityRetryController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.DO_BACK_END_EDITING.ACTION)) { return;//from ww w.ja va2s. co m } VitroRequest vreq = new VitroRequest(request); String siteAdminUrl = vreq.getContextPath() + Controllers.SITE_ADMIN; //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); epo.setBeanClass(Individual.class); epo.setImplementationClass(IndividualImpl.class); String action = null; if (epo.getAction() == null) { action = "insert"; epo.setAction("insert"); } else { action = epo.getAction(); } LoginStatusBean loginBean = LoginStatusBean.getBean(request); WebappDaoFactory myWebappDaoFactory = getWebappDaoFactory(loginBean.getUserURI()); IndividualDao ewDao = myWebappDaoFactory.getIndividualDao(); epo.setDataAccessObject(ewDao); VClassDao vcDao = myWebappDaoFactory.getVClassDao(); VClassGroupDao cgDao = myWebappDaoFactory.getVClassGroupDao(); DataPropertyDao dpDao = myWebappDaoFactory.getDataPropertyDao(); Individual individualForEditing = null; if (epo.getUseRecycledBean()) { individualForEditing = (Individual) epo.getNewBean(); } else { String uri = vreq.getParameter("uri"); if (uri != null) { try { individualForEditing = (Individual) ewDao.getIndividualByURI(uri); action = "update"; epo.setAction("update"); } catch (NullPointerException e) { log.error("Need to implement 'record not found' error message."); } } else { individualForEditing = new IndividualImpl(); if (vreq.getParameter("VClassURI") != null) { individualForEditing.setVClassURI(vreq.getParameter("VClassURI")); } } epo.setOriginalBean(individualForEditing); //make a simple mask for the entity's id Object[] simpleMaskPair = new Object[2]; simpleMaskPair[0] = "URI"; simpleMaskPair[1] = individualForEditing.getURI(); epo.getSimpleMask().add(simpleMaskPair); } //set any validators LinkedList lnList = new LinkedList(); lnList.add(new RequiredFieldValidator()); epo.getValidatorMap().put("Name", lnList); //make a postinsert pageforwarder that will send us to a new entity's fetch screen epo.setPostInsertPageForwarder(new EntityInsertPageForwarder()); epo.setPostDeletePageForwarder(new UrlForwarder(siteAdminUrl)); //set the getMethod so we can retrieve a new bean after we've inserted it try { Class[] args = new Class[1]; args[0] = String.class; epo.setGetMethod(ewDao.getClass().getDeclaredMethod("getIndividualByURI", args)); } catch (NoSuchMethodException e) { log.error("EntityRetryController could not find the entityByURI method in the dao"); } epo.setIdFieldName("URI"); epo.setIdFieldClass(String.class); HashMap hash = new HashMap(); if (individualForEditing.getVClassURI() == null) { // we need to do a special thing here to make an option list with option groups for the classgroups. List classGroups = cgDao.getPublicGroupsWithVClasses(true, true, false); // order by displayRank, include uninstantiated classes, don't get the counts of individuals Iterator classGroupIt = classGroups.iterator(); ListOrderedMap optGroupMap = new ListOrderedMap(); while (classGroupIt.hasNext()) { VClassGroup group = (VClassGroup) classGroupIt.next(); List classes = group.getVitroClassList(); optGroupMap.put(group.getPublicName(), FormUtils.makeOptionListFromBeans(classes, "URI", "Name", individualForEditing.getVClassURI(), null, false)); } hash.put("VClassURI", optGroupMap); } else { VClass vClass = null; Option opt = null; try { vClass = vcDao.getVClassByURI(individualForEditing.getVClassURI()); } catch (Exception e) { } if (vClass != null) { opt = new Option(vClass.getURI(), vClass.getName(), true); } else { opt = new Option(individualForEditing.getVClassURI(), individualForEditing.getVClassURI(), true); } List<Option> optList = new LinkedList<Option>(); optList.add(opt); hash.put("VClassURI", optList); } hash.put("HiddenFromDisplayBelowRoleLevelUsingRoleUri", RoleLevelOptionsSetup.getDisplayOptionsList(individualForEditing)); hash.put("ProhibitedFromUpdateBelowRoleLevelUsingRoleUri", RoleLevelOptionsSetup.getUpdateOptionsList(individualForEditing)); hash.put("HiddenFromPublishBelowRoleLevelUsingRoleUri", RoleLevelOptionsSetup.getPublishOptionsList(individualForEditing)); FormObject foo = new FormObject(); foo.setOptionLists(hash); ListOrderedMap dpMap = new ListOrderedMap(); //make dynamic datatype property fields List<VClass> vclasses = individualForEditing.getVClasses(true); if (vclasses == null) { vclasses = new ArrayList<VClass>(); if (individualForEditing.getVClassURI() != null) { try { VClass cls = vreq.getUnfilteredWebappDaoFactory().getVClassDao() .getVClassByURI(individualForEditing.getVClassURI()); if (cls != null) { vclasses.add(cls); } } catch (Exception e) { } } } List<DataProperty> allApplicableDataprops = new ArrayList<DataProperty>(); for (VClass cls : vclasses) { List<DataProperty> dataprops = dpDao.getDataPropertiesForVClass(cls.getURI()); for (DataProperty dp : dataprops) { boolean notDuplicate = true; for (DataProperty existingDp : allApplicableDataprops) { if (existingDp.getURI().equals(dp.getURI())) { notDuplicate = false; break; } } if (notDuplicate) { allApplicableDataprops.add(dp); } } } Collections.sort(allApplicableDataprops); if (allApplicableDataprops != null) { Iterator<DataProperty> datapropsIt = allApplicableDataprops.iterator(); while (datapropsIt.hasNext()) { DataProperty d = datapropsIt.next(); if (!dpMap.containsKey(d.getURI())) { dpMap.put(d.getURI(), d); } } if (individualForEditing.getDataPropertyList() != null) { Iterator<DataProperty> existingDps = individualForEditing.getDataPropertyList().iterator(); while (existingDps.hasNext()) { DataProperty existingDp = existingDps.next(); // Since the edit form begins with a "name" field, which gets saved as the rdfs:label, // do not want to include the label as well. if (!existingDp.getPublicName().equals("label")) { dpMap.put(existingDp.getURI(), existingDp); } } } List<DynamicField> dynamicFields = new ArrayList(); Iterator<String> dpHashIt = dpMap.orderedMapIterator(); while (dpHashIt.hasNext()) { String uri = dpHashIt.next(); DataProperty dp = (DataProperty) dpMap.get(uri); DynamicField dynamo = new DynamicField(); dynamo.setName(dp.getPublicName()); dynamo.setTable("DataPropertyStatement"); dynamo.setVisible(dp.getDisplayLimit()); dynamo.setDeleteable(true); DynamicFieldRow rowTemplate = new DynamicFieldRow(); Map parameterMap = new HashMap(); parameterMap.put("DatatypePropertyURI", dp.getURI()); rowTemplate.setParameterMap(parameterMap); dynamo.setRowTemplate(rowTemplate); try { Iterator<DataPropertyStatement> existingValues = dp.getDataPropertyStatements().iterator(); while (existingValues.hasNext()) { DataPropertyStatement existingValue = existingValues.next(); DynamicFieldRow row = new DynamicFieldRow(); //TODO: UGH //row.setId(existingValue.getId()); row.setParameterMap(parameterMap); row.setValue(existingValue.getData()); if (dynamo.getRowList() == null) dynamo.setRowList(new ArrayList()); dynamo.getRowList().add(row); } } catch (NullPointerException npe) { //whatever } if (dynamo.getRowList() == null) dynamo.setRowList(new ArrayList()); dynamo.getRowList().add(rowTemplate); dynamicFields.add(dynamo); } foo.setDynamicFields(dynamicFields); } foo.setErrorMap(epo.getErrMsgMap()); epo.setFormObject(foo); // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateFormat minutesOnlyDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); DateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd"); FormUtils.populateFormFromBean(individualForEditing, action, epo, foo, epo.getBadValueMap()); List cList = new ArrayList(); cList.add(new IndividualDataPropertyStatementProcessor()); //cList.add(new SearchReindexer()); // handled for now by SearchReindexingListener on model epo.setChangeListenerList(cList); epo.getAdditionalDaoMap().put("DataPropertyStatement", myWebappDaoFactory.getDataPropertyStatementDao()); // EntityDatapropProcessor will look for this epo.getAdditionalDaoMap().put("DataProperty", myWebappDaoFactory.getDataPropertyDao()); // EntityDatapropProcessor will look for this ApplicationBean appBean = vreq.getAppBean(); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp"); request.setAttribute("formJsp", "/templates/edit/specific/entity_retry.jsp"); request.setAttribute("epoKey", epo.getKey()); request.setAttribute("title", "Individual Editing Form"); request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + appBean.getThemeDir() + "css/edit.css\"/>"); request.setAttribute("scripts", "/js/edit/entityRetry.js"); // NC Commenting this out for now. Going to pass on DWR for moniker and use jQuery instead // request.setAttribute("bodyAttr"," onLoad=\"monikerInit()\""); request.setAttribute("_action", action); request.setAttribute("unqualifiedClassName", "Individual"); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error("EntityRetryController could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:org.jahia.services.content.ConflictResolver.java
private List<Diff> compare(JCRNodeWrapper sourceNode, JCRNodeWrapper targetNode, String basePath) throws RepositoryException { List<Diff> diffs = new ArrayList<Diff>(); boolean remotelyPublished = targetNode.isNodeType("jmix:remotelyPublished"); if (!remotelyPublished) { final ListOrderedMap targetUuids = getChildEntries(targetNode, targetNode.getSession()); final ListOrderedMap sourceUuids = getChildEntries(sourceNode, sourceNode.getSession()); if (!targetUuids.values().equals(sourceUuids.values())) { for (Iterator<?> iterator = sourceUuids.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); if (targetUuids.containsKey(key) && !targetUuids.get(key).equals(sourceUuids.get(key))) { diffs.add(new ChildRenamedDiff(key, addPath(basePath, (String) targetUuids.get(key)), addPath(basePath, (String) sourceUuids.get(key)))); }/*from w w w. j a v a2 s .c o m*/ } } // Child nodes if (!targetUuids.keyList().equals(sourceUuids.keyList())) { @SuppressWarnings("unchecked") List<String> addedUuids = new ArrayList<String>(sourceUuids.keySet()); addedUuids.removeAll(targetUuids.keySet()); @SuppressWarnings("unchecked") List<String> removedUuids = new ArrayList<String>(targetUuids.keySet()); removedUuids.removeAll(sourceUuids.keySet()); // Ordering if (targetNode.getPrimaryNodeType().hasOrderableChildNodes()) { Map<String, String> newOrdering = getOrdering(sourceUuids, Collections.<String>emptyList()); @SuppressWarnings("unchecked") List<String> oldUuidsList = new ArrayList<String>(targetUuids.keySet()); oldUuidsList.removeAll(removedUuids); @SuppressWarnings("unchecked") List<String> newUuidsList = new ArrayList<String>(sourceUuids.keySet()); newUuidsList.removeAll(addedUuids); if (!oldUuidsList.equals(newUuidsList)) { for (int i = 1; i < oldUuidsList.size(); i++) { String x = oldUuidsList.get(i); int j = i; while (j > 0 && sourceUuids.indexOf(oldUuidsList.get(j - 1)) > sourceUuids.indexOf(x)) { oldUuidsList.set(j, oldUuidsList.get(j - 1)); j--; } if (j != i) { String orderBeforeUuid = (j + 1 == oldUuidsList.size()) ? null : oldUuidsList.get(j + 1); diffs.add(new ChildNodeReorderedDiff(x, orderBeforeUuid, addPath(basePath, (String) sourceUuids.get(x)), (String) sourceUuids.get(orderBeforeUuid), newOrdering)); logger.debug("reorder " + sourceUuids.get(x) + " before " + sourceUuids.get(orderBeforeUuid)); oldUuidsList.set(j, x); } } } } // Removed nodes for (String removedUuid : removedUuids) { try { this.sourceNode.getSession().getNodeByUUID(removedUuid); } catch (ItemNotFoundException e) { // Item has been moved diffs.add(new ChildRemovedDiff(removedUuid, addPath(basePath, (String) targetUuids.get(removedUuid)), removedUuid)); } } // Added nodes for (String addedUuid : addedUuids) { diffs.add(new ChildAddedDiff(addedUuid, addPath(basePath, (String) sourceUuids.get(addedUuid)), addedUuid.equals(sourceUuids.lastKey()) ? null : (String) sourceUuids .get(sourceUuids.get(sourceUuids.indexOf(addedUuid) + 1)))); } } } PropertyIterator targetProperties = targetNode.getProperties(); while (targetProperties.hasNext()) { JCRPropertyWrapper targetProperty = (JCRPropertyWrapper) targetProperties.next(); String propertyName = targetProperty.getName(); if (IGNORED_PROPRTIES.contains(propertyName)) { continue; } if (!sourceNode.hasProperty(propertyName)) { if (targetProperty.isMultiple()) { Value[] values = targetProperty.getRealValues(); for (Value value : values) { diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value)); } } else { diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName), null)); } } else { JCRPropertyWrapper sourceProperty = sourceNode.getProperty(propertyName); if (targetProperty.isMultiple() != sourceProperty.isMultiple()) { throw new RepositoryException(); } if (targetProperty.isMultiple()) { List<? extends Value> targetValues = Arrays.asList(targetProperty.getRealValues()); List<? extends Value> sourceValues = Arrays.asList(sourceProperty.getRealValues()); Map<String, Value> addedValues = new HashMap<String, Value>(); for (Value value : sourceValues) { addedValues.put(value.getString(), value); } for (Value value : targetValues) { addedValues.remove(value.getString()); } for (Value value : addedValues.values()) { diffs.add(new PropertyAddedDiff(addPath(basePath, propertyName), value)); } Map<String, Value> removedValues = new HashMap<String, Value>(); for (Value value : targetValues) { removedValues.put(value.getString(), value); } for (Value value : sourceValues) { removedValues.remove(value.getString()); } for (Value value : removedValues.values()) { diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value)); } } else { if (!equalsValue(targetProperty.getRealValue(), sourceProperty.getRealValue())) { diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName), sourceProperty.getRealValue())); } } } } PropertyIterator sourceProperties = sourceNode.getProperties(); while (sourceProperties.hasNext()) { JCRPropertyWrapper sourceProperty = (JCRPropertyWrapper) sourceProperties.next(); String propertyName = sourceProperty.getName(); if (IGNORED_PROPRTIES.contains(propertyName)) { continue; } if (!targetNode.hasProperty(propertyName)) { if (sourceProperty.isMultiple()) { Value[] values = sourceProperty.getRealValues(); for (Value value : values) { diffs.add(new PropertyAddedDiff(addPath(basePath, sourceProperty.getName()), value)); } } else { diffs.add(new PropertyChangedDiff(addPath(basePath, sourceProperty.getName()), sourceProperty.getRealValue())); } } } for (Diff diff : new ArrayList<Diff>(diffs)) { if (diff instanceof PropertyAddedDiff && ((PropertyAddedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) { diffs.remove(diff); diffs.add(0, diff); } } for (Diff diff : new ArrayList<Diff>(diffs)) { if (diff instanceof PropertyRemovedDiff && ((PropertyRemovedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) { diffs.remove(diff); diffs.add(0, diff); } } if (!remotelyPublished) { NodeIterator targetSubNodes = targetNode.getNodes(); while (targetSubNodes.hasNext()) { JCRNodeWrapper targetSubNode = (JCRNodeWrapper) targetSubNodes.next(); if (sourceNode.hasNode(targetSubNode.getName()) && !targetSubNode.isVersioned() && !sourceNode.getNode(targetSubNode.getName()).isVersioned() && JCRPublicationService.supportsPublication(targetSubNode.getSession(), targetSubNode)) { diffs.addAll(compare(sourceNode.getNode(targetSubNode.getName()), targetSubNode, addPath(basePath, targetSubNode.getName()))); } } } return diffs; }
From source file:org.s23m.cell.repository.RelationalDatabaseRepository.java
private void addUUIDs(final ResultSet rs, final ListOrderedMap uuidMap) throws SQLException { if (!uuidMap.containsKey(ROOT_URR)) { final String rootUrr = rs.getString(ROOT_URR); //$NON-NLS-1$ uuidMap.put(rootUrr, rootUrr);// w w w .ja v a2s.c om } for (int n = 1; n <= MAX_DEPTH; n++) { final String urr = rs.getString("lev" + n); //$NON-NLS-1$ if (urr != null) { if (!uuidMap.containsKey(urr)) { uuidMap.put(urr, urr); } } else { break; } } }
From source file:org.s23m.cell.repository.RelationalDatabaseRepository.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private Map getDependentInstanceUUIDs(final String uuid) throws SQLException { final CallableStatement fetchContainedInstanceUUIDs = execueteUUIDQuery("getDependentInstanceUUIDs", uuid); Timer.getInstance().start("getDependentInstanceUUIDs"); //$NON-NLS-1$ final ResultSet rs = fetchContainedInstanceUUIDs.getResultSet(); final ListOrderedMap uuidMap = new ListOrderedMap(); while (rs.next()) { final String urr = rs.getString("urr"); if (urr != null && !uuidMap.containsKey(urr)) { uuidMap.put(urr, urr);//w w w. ja v a 2 s . c om } } System.err.println("Time taken for doing getDependentInstanceUUIDs: " //$NON-NLS-1$ + Timer.getInstance().time("getDependentInstanceUUIDs", TimeUnit.MILLISECONDS)); rs.close(); fetchContainedInstanceUUIDs.close(); return uuidMap; }