List of usage examples for java.util List equals
boolean equals(Object o);
From source file:org.alfresco.repo.version.VersionServiceImplTest.java
/** * Sets the versionService to be one that has is db ids out of order * so would normally have versions displayed in the wrong order. * @param versionComparatorClass name of class to correct the situation. *//*from w w w . j a va2s .c o m*/ private void setOutOfOrderIdsVersionService(String versionComparatorClass) { Version2ServiceImpl versionService = new Version2ServiceImpl() { @Override protected List<Version> getAllVersions(NodeRef versionHistoryRef) { List<Version> versions = super.getAllVersions(versionHistoryRef); if (versions.size() > 1) { // Make sure the order changes List<Version> copy = new ArrayList<Version>(versions); do { Collections.shuffle(versions); } while (versions.equals(copy)); } return versions; } }; versionService.setNodeService(nodeService); versionService.setDbNodeService(dbNodeService); // mtAwareNodeService versionService.setSearcher(versionSearchService); versionService.setDictionaryService(dictionaryService); versionService.setPolicyComponent(policyComponent); versionService.setPolicyBehaviourFilter(policyBehaviourFilter); versionService.setPermissionService(permissionService); versionService.setVersionComparatorClass(versionComparatorClass); versionService.initialise(); setVersionService(versionService); }
From source file:com.flexive.tests.embedded.SearchEngineTest.java
@Test public void versionFilterTest() throws FxApplicationException { final List<FxPK> allVersions = getPksForVersion(VersionFilter.ALL); final List<FxPK> liveVersions = getPksForVersion(VersionFilter.LIVE); final List<FxPK> maxVersions = getPksForVersion(VersionFilter.MAX); Collections.sort(allVersions); Collections.sort(liveVersions); Collections.sort(maxVersions); assertTrue(allVersions.size() > 0, "All versions result must not be empty"); assertTrue(liveVersions.size() > 0, "Live versions result must not be empty"); assertTrue(maxVersions.size() > 0, "Max versions result must not be empty"); assertTrue(allVersions.size() > liveVersions.size(), "Expected more than only live versions"); assertTrue(allVersions.size() > maxVersions.size(), "Expected more than only max versions"); assertTrue(!liveVersions.equals(maxVersions), "Expected different results for max and live version filter"); for (FxPK pk : liveVersions) { final FxContent content = getContentEngine().load(pk); assertTrue(content.isLiveVersion(), "Expected live version for " + pk); }/*www.ja v a 2 s.co m*/ for (FxPK pk : maxVersions) { final FxContent content = getContentEngine().load(pk); assertTrue(content.isMaxVersion(), "Expected max version for " + pk); assertTrue(content.getVersion() == 1 || !content.isLiveVersion()); } }
From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java
@Test public void testMutateRandomGeneGroupWithAllIndicesUsed() { MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome(); List<MockGene> originalGenes = new ArrayList<>(); MockGene mockGene1 = new MockGene(); mockGene1.addSequence(new MockSequence("g")); mockGene1.addSequence(new MockSequence("e")); mockGene1.addSequence(new MockSequence("o")); mockGene1.addSequence(new MockSequence("r")); mockGene1.addSequence(new MockSequence("g")); mockGene1.addSequence(new MockSequence("e")); mockKeylessChromosome.addGene(mockGene1); originalGenes.add(mockGene1);/*from w w w . j a v a 2 s .c o m*/ MockGene mockGene2 = new MockGene(); mockGene2.addSequence(new MockSequence("b")); mockGene2.addSequence(new MockSequence("e")); mockGene2.addSequence(new MockSequence("l")); mockGene2.addSequence(new MockSequence("d")); mockGene2.addSequence(new MockSequence("e")); mockGene2.addSequence(new MockSequence("n")); mockKeylessChromosome.addGene(mockGene2); originalGenes.add(mockGene2); MockGene mockGene3 = new MockGene(); mockGene3.addSequence(new MockSequence("i")); mockGene3.addSequence(new MockSequence("s")); mockKeylessChromosome.addGene(mockGene3); originalGenes.add(mockGene3); MockGene mockGene4 = new MockGene(); mockGene4.addSequence(new MockSequence("a")); mockGene4.addSequence(new MockSequence("w")); mockGene4.addSequence(new MockSequence("e")); mockGene4.addSequence(new MockSequence("s")); mockGene4.addSequence(new MockSequence("o")); mockGene4.addSequence(new MockSequence("m")); mockGene4.addSequence(new MockSequence("e")); mockKeylessChromosome.addGene(mockGene4); originalGenes.add(mockGene4); List<Integer> availableIndices = new ArrayList<Integer>(); groupMutationAlgorithm.mutateRandomGeneGroup(mockKeylessChromosome, availableIndices, 2); assertTrue(originalGenes.equals(mockKeylessChromosome.getGenes())); assertEquals(0, availableIndices.size()); assertEquals(21, mockKeylessChromosome.actualSize().intValue()); verifyZeroInteractions(geneDaoMock); verify(logMock, times(1)).warn(anyString()); verifyNoMoreInteractions(logMock); }
From source file:org.apache.hadoop.hive.metastore.TestHiveMetaStore.java
public void testNameMethods() { Map<String, String> spec = new LinkedHashMap<String, String>(); spec.put("ds", "2008-07-01 14:13:12"); spec.put("hr", "14"); List<String> vals = new ArrayList<String>(); for (String v : spec.values()) { vals.add(v);/*from w w w. jav a2 s. c o m*/ } String partName = "ds=2008-07-01 14%3A13%3A12/hr=14"; try { List<String> testVals = client.partitionNameToVals(partName); assertTrue("Values from name are incorrect", vals.equals(testVals)); Map<String, String> testSpec = client.partitionNameToSpec(partName); assertTrue("Spec from name is incorrect", spec.equals(testSpec)); List<String> emptyVals = client.partitionNameToVals(""); assertTrue("Values should be empty", emptyVals.size() == 0); Map<String, String> emptySpec = client.partitionNameToSpec(""); assertTrue("Spec should be empty", emptySpec.size() == 0); } catch (Exception e) { assert (false); } }
From source file:com.virtusa.akura.common.controller.ManageSpecialEventsController.java
/** * Create or update SpecialEvent details. * //w w w . j a v a 2 s. com * @param request - HttpServletRequest * @param model - ModelMap * @param specialEvents - SpecialEvents object * @param bindingResult - BindingResult * @return name of the view which is redirected to. * @throws AkuraAppException - if error occurs when save or update a FaithLifeRating instance. */ @RequestMapping(value = "/saveOrUpdateSpecialEvent.htm", method = RequestMethod.POST) public String saveOrUpdateSpecialEvent(@ModelAttribute(MODEL_ATT_SPECIAL_EVENT) SpecialEvents specialEvents, BindingResult bindingResult, HttpServletRequest request, ModelMap model) throws AkuraAppException { String[] toList = null; if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); } // Trim the special event name specialEvents.setName(specialEvents.getName().trim()); specialEventsValidator.validate(specialEvents, bindingResult); int intSpecialEventId = specialEvents.getSpecialEventsId(); String strMessage = null; SpecialEvents spEvent; String finalToList = null; if (bindingResult.hasErrors()) { if (specialEvents.getSpecialEventsId() != 0) { spEvent = commonService.findSpecialEventsById(specialEvents.getSpecialEventsId()); model.addAttribute(MODEL_ATT_SELECTED_OBJECT, spEvent); } errorMassage(model, specialEvents); if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); finalToList = this.toListToString(specialEvents, toList); } model.addAttribute(MODEL_ATT_OBJECT_PARTICIPANT, finalToList); model.addAttribute(MODEL_ATT_OBJECT_FORM, specialEvents); return VIEW_GET_CREATE_SPECIAL_EVENTS; } else { if (toList == null) { if (specialEvents.getSpecialEventsId() != 0) { spEvent = commonService.findSpecialEventsById(specialEvents.getSpecialEventsId()); model.addAttribute(MODEL_ATT_SELECTED_OBJECT, spEvent); } errorMassage(model, specialEvents); if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); finalToList = this.toListToString(specialEvents, toList); } model.addAttribute(MODEL_ATT_OBJECT_PARTICIPANT, finalToList); strMessage = new ErrorMsgLoader().getErrorMessage(AkuraWebConstant.MANDATORY_FIELD_ERROR_CODE); model.addAttribute(MODEL_ATT_MESSAGE, strMessage); model.addAttribute(MODEL_ATT_OBJECT_FORM, specialEvents); return VIEW_GET_CREATE_SPECIAL_EVENTS; } else { try { if (commonService.isExistsSpecialEvents(specialEvents)) { if (intSpecialEventId != 0) { List<String> toListt = new ArrayList<String>(); spEvent = commonService.findSpecialEventsById(intSpecialEventId); if (spEvent.getSpecialEventsId() == specialEvents.getSpecialEventsId() && spEvent.getName().equalsIgnoreCase(specialEvents.getName()) && (spEvent.getDate().compareTo(specialEvents.getDate())) == 0 && spEvent.getParticipantCategory().getParticipantCategoryId() == specialEvents .getParticipantCategory().getParticipantCategoryId() && spEvent.getDescription().equalsIgnoreCase(specialEvents.getDescription())) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); List<String> toListtt = Arrays.asList(toList); List<SpecialEventsParticipation> participants = commonService .getParticipantListBySpecialEvent(spEvent); String participantId = null; int partId = 0; for (SpecialEventsParticipation participant : participants) { if (spEvent.getParticipantCategory() .getParticipantCategoryId() == AkuraConstant.PARAM_INDEX_ONE) { partId = participant.getClassGrade().getClassGradeId(); } else if (spEvent.getParticipantCategory() .getParticipantCategoryId() == AkuraConstant.PARAM_INDEX_TWO) { partId = participant.getSportCategory().getSportCategoryId(); } else if (spEvent.getParticipantCategory() .getParticipantCategoryId() == AkuraConstant.PARAM_INDEX_THREE) { partId = participant.getClubSociety().getClubSocietyId(); } participantId = String.valueOf(partId); toListt.add(participantId); } if (toListt.equals(toListtt)) { return VIEW_GET_CREATE_SPECIAL_EVENTS; } } // editing selected object with detail or participation list if (spEvent.getName().equalsIgnoreCase(specialEvents.getName()) && (spEvent.getDate().compareTo(specialEvents.getDate())) == 0) { // deleting all specilEvents participation list related to given List<SpecialEventsParticipation> participants = commonService .getParticipantListBySpecialEvent(spEvent); commonService.deleteAllSpecialEventsParticipation(participants); commonService.editSpecialEvents(specialEvents); createSpecialEventsParticipant(toList, spEvent); return VIEW_POST_CREAT_SPECIAL_EVENTS; } else { spEvent = commonService.findSpecialEventsById(specialEvents.getSpecialEventsId()); if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); finalToList = this.toListToString(specialEvents, toList); } model.addAttribute(MODEL_ATT_OBJECT_PARTICIPANT, finalToList); model.addAttribute(MODEL_ATT_SELECTED_OBJECT, spEvent); model.addAttribute(SHOW_EDIT_SECTION, SHOW_EDIT_SECTION); model.addAttribute(MODEL_ATT_SELECTED_OBJECT_ID, intSpecialEventId); bindingResult.rejectValue("specialEventsId", AkuraWebConstant.ALREADY_EXIST_ERROR_CODE); return VIEW_GET_CREATE_SPECIAL_EVENTS; } } else { model.addAttribute(MODEL_ATT_SELECTED_OBJECT_ID, intSpecialEventId); errorMassage(model, specialEvents); if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); finalToList = this.toListToString(specialEvents, toList); } model.addAttribute(MODEL_ATT_OBJECT_PARTICIPANT, finalToList); model.addAttribute(SHOW_EDIT_SECTION, SHOW_EDIT_SECTION); bindingResult.rejectValue("specialEventsId", AkuraWebConstant.ALREADY_EXIST_ERROR_CODE); return VIEW_GET_CREATE_SPECIAL_EVENTS; } } else { if (intSpecialEventId == 0) { spEvent = commonService.addSpecialEvents(specialEvents); createSpecialEventsParticipant(toList, spEvent); } else { spEvent = commonService.findSpecialEventsById(intSpecialEventId); SpecialEvents speEvent = commonService.findSpecialEventsById(intSpecialEventId); // deleting all specilEvents participation list related to given specialEvent List<SpecialEventsParticipation> participants = commonService .getParticipantListBySpecialEvent(speEvent); commonService.deleteAllSpecialEventsParticipation(participants); commonService.editSpecialEvents(specialEvents); createSpecialEventsParticipant(toList, speEvent); } } } catch (AkuraAppException e) { if (e.getCause() instanceof DataIntegrityViolationException) { strMessage = new ErrorMsgLoader().getErrorMessage(REF_UI_SPECIAL_EVENT_EDIT); errorMassage(model, specialEvents); // SpecialEvents newSpecialEvents = new SpecialEvents(); if (request.getParameterValues(REQUEST_SELECTED_LIST) != null) { toList = request.getParameterValues(REQUEST_SELECTED_LIST); finalToList = this.toListToString(specialEvents, toList); } model.addAttribute(MODEL_ATT_OBJECT_PARTICIPANT, finalToList); model.addAttribute(MODEL_ATT_SELECTED_OBJECT_ID, intSpecialEventId); model.addAttribute(SHOW_EDIT_SECTION, SHOW_EDIT_SECTION); model.addAttribute(MODEL_ATT_MESSAGE, strMessage); // model.addAttribute("specialEvents", newSpecialEvents); return VIEW_GET_CREATE_SPECIAL_EVENTS; } else { throw e; } } } } return VIEW_POST_CREAT_SPECIAL_EVENTS; }
From source file:com.ciphertool.genetics.algorithms.mutation.GroupMutationAlgorithmTest.java
@Test public void testMutateRandomGeneGroupWithUsedIndex() { MockKeylessChromosome mockKeylessChromosome = new MockKeylessChromosome(); List<MockGene> originalGenes = new ArrayList<>(); MockGene mockGene1 = new MockGene(); mockGene1.addSequence(new MockSequence("g")); mockGene1.addSequence(new MockSequence("e")); mockGene1.addSequence(new MockSequence("o")); mockGene1.addSequence(new MockSequence("r")); mockGene1.addSequence(new MockSequence("g")); mockGene1.addSequence(new MockSequence("e")); mockKeylessChromosome.addGene(mockGene1); originalGenes.add(mockGene1);/* w w w. j a v a 2 s . c o m*/ MockGene mockGene2 = new MockGene(); mockGene2.addSequence(new MockSequence("b")); mockGene2.addSequence(new MockSequence("e")); mockGene2.addSequence(new MockSequence("l")); mockGene2.addSequence(new MockSequence("d")); mockGene2.addSequence(new MockSequence("e")); mockGene2.addSequence(new MockSequence("n")); mockKeylessChromosome.addGene(mockGene2); originalGenes.add(mockGene2); MockGene mockGene3 = new MockGene(); mockGene3.addSequence(new MockSequence("i")); mockGene3.addSequence(new MockSequence("s")); mockKeylessChromosome.addGene(mockGene3); originalGenes.add(mockGene3); MockGene mockGene4 = new MockGene(); mockGene4.addSequence(new MockSequence("a")); mockGene4.addSequence(new MockSequence("w")); mockGene4.addSequence(new MockSequence("e")); mockGene4.addSequence(new MockSequence("s")); mockGene4.addSequence(new MockSequence("o")); mockGene4.addSequence(new MockSequence("m")); mockGene4.addSequence(new MockSequence("e")); mockKeylessChromosome.addGene(mockGene4); originalGenes.add(mockGene4); MockGene mockGeneToReturn = new MockGene(); mockGeneToReturn.addSequence(new MockSequence("x")); mockGeneToReturn.addSequence(new MockSequence("y")); mockGeneToReturn.addSequence(new MockSequence("z")); when(geneDaoMock.findRandomGene(same(mockKeylessChromosome))).thenReturn(mockGeneToReturn); List<Integer> availableIndices = new ArrayList<Integer>(); availableIndices.add(0); availableIndices.add(1); int originalAvailableIndicesSize = availableIndices.size(); groupMutationAlgorithm.mutateRandomGeneGroup(mockKeylessChromosome, availableIndices, 2); assertFalse(originalGenes.equals(mockKeylessChromosome.getGenes())); assertTrue(originalAvailableIndicesSize > availableIndices.size()); assertEquals(21, mockKeylessChromosome.actualSize().intValue()); int indicesRemoved = 0; for (Integer availableIndex : availableIndices) { assertTrue( originalGenes.contains(mockKeylessChromosome.getGenes().get(availableIndex - indicesRemoved))); mockKeylessChromosome.removeGene(availableIndex - indicesRemoved); indicesRemoved++; } assertTrue(mockKeylessChromosome.getGenes().size() > 0); int mockChromosomeSizeMinusTwo = mockKeylessChromosome.getGenes().size() - 2; for (int i = 0; i < mockChromosomeSizeMinusTwo; i++) { assertEquals(mockGeneToReturn, mockKeylessChromosome.getGenes().get(i)); } assertEquals(originalGenes.get(2), mockKeylessChromosome.getGenes().get(mockKeylessChromosome.getGenes().size() - 2)); assertEquals(originalGenes.get(3), mockKeylessChromosome.getGenes().get(mockKeylessChromosome.getGenes().size() - 1)); verify(geneDaoMock, atLeastOnce()).findRandomGene(same(mockKeylessChromosome)); verify(geneDaoMock, atMost(4)).findRandomGene(same(mockKeylessChromosome)); verify(geneDaoMock, never()).findRandomGeneOfLength(same(mockKeylessChromosome), anyInt()); verifyZeroInteractions(logMock); }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
private void updateChildren(Node node, JsonNode jsonNode, VersionableChanges changes) throws RepositoryException { Session session = node.getSession(); // Get the existing children ... Map<String, Node> existingChildNames = new LinkedHashMap<>(); List<String> existingChildrenToUpdate = new ArrayList<>(); NodeIterator childIter = node.getNodes(); while (childIter.hasNext()) { Node child = childIter.nextNode(); String childName = nameOf(child); existingChildNames.put(childName, child); existingChildrenToUpdate.add(childName); }/*from ww w . j av a 2s .c om*/ //keep track of the old/new order of children to be able to perform reorderings List<String> newChildrenToUpdate = new ArrayList<>(); List<JSONChild> children = getChildren(jsonNode); for (JSONChild jsonChild : children) { String childName = jsonChild.getNameWithSNS(); JsonNode child = jsonChild.getBody(); // Find the existing node ... if (node.hasNode(childName)) { // The node exists, so get it and update it ... Node childNode = node.getNode(childName); String childNodeName = nameOf(childNode); newChildrenToUpdate.add(childNodeName); updateNode(childNode, child, changes); existingChildNames.remove(childNodeName); } else { //try to see if the child name is actually an identifier try { Node childNode = session.getNodeByIdentifier(childName); String childNodeName = nameOf(childNode); if (childNode.getParent().getIdentifier().equals(node.getIdentifier())) { //this is an existing child of the current node, referenced via an identifier newChildrenToUpdate.add(childNodeName); updateNode(childNode, child, changes); existingChildNames.remove(childNodeName); } else { //this is a child belonging to another node if (childNode.isNodeType("mix:shareable")) { //if it's a shared node, we can't clone it because clone is not a session-scoped operation logger.warn( "The node {0} with the id {1} is a shared node belonging to another parent. It cannot be changed via the update operation", childNode.getPath(), childNode.getIdentifier()); } else { //move the node into this parent session.move(childNode.getPath(), node.getPath() + "/" + childNodeName); } } } catch (ItemNotFoundException e) { //the child name is not a valid identifier, so treat it as a new child addNode(node, childName, child); } } } // Remove the children in reverse order (starting with the last child to be removed) ... LinkedList<Node> childNodes = new LinkedList<Node>(existingChildNames.values()); while (!childNodes.isEmpty()) { Node child = childNodes.removeLast(); existingChildrenToUpdate.remove(child.getIdentifier()); child.remove(); } // Do any necessary reorderings if (newChildrenToUpdate.equals(existingChildrenToUpdate)) { //no order changes exist return; } for (int i = 0; i < newChildrenToUpdate.size() - 1; i++) { String startNodeName = newChildrenToUpdate.get(i); int startNodeOriginalPosition = existingChildrenToUpdate.indexOf(startNodeName); assert startNodeOriginalPosition != -1; for (int j = i + 1; j < newChildrenToUpdate.size(); j++) { String nodeName = newChildrenToUpdate.get(j); int nodeOriginalPosition = existingChildrenToUpdate.indexOf(nodeName); assert nodeOriginalPosition != -1; if (startNodeOriginalPosition > nodeOriginalPosition) { //the start node should be moved *before* this node node.orderBefore(startNodeName, nodeName); } } } }
From source file:org.jahia.ajax.gwt.content.server.JahiaContentManagementServiceImpl.java
/** * Save node with properties, acl and new ordered children * * @param node/*w w w . j ava2 s . com*/ * @param acl * @param langCodeProperties * @param sharedProperties * @param removedTypes * @throws GWTJahiaServiceException */ @Override @SuppressWarnings("unchecked") public RpcMap saveNode(GWTJahiaNode node, GWTJahiaNodeACL acl, Map<String, List<GWTJahiaNodeProperty>> langCodeProperties, List<GWTJahiaNodeProperty> sharedProperties, Set<String> removedTypes) throws GWTJahiaServiceException { RpcMap result = new RpcMap(); final JCRSessionWrapper jcrSessionWrapper = retrieveCurrentSession(); try { JCRNodeWrapper nodeWrapper = jcrSessionWrapper.getNodeByUUID(node.getUUID()); if (!nodeWrapper.getName().equals(JCRContentUtils.escapeLocalNodeName(node.getName()))) { String name = contentManager.findAvailableName(nodeWrapper.getParent(), JCRContentUtils.escapeLocalNodeName(node.getName())); nodeWrapper.rename(name); jcrSessionWrapper.save(); } node.setName(nodeWrapper.getName()); node.setPath(nodeWrapper.getPath()); // setLock(Arrays.asList(node.getPath()), false); Iterator<String> langCode = langCodeProperties.keySet().iterator(); try { List<JCRSessionWrapper> sessions = new ArrayList<>(); JCRSessionWrapper session = retrieveCurrentSession(null); sessions.add(session); // save shared properties properties.saveProperties(Arrays.asList(node), sharedProperties, removedTypes, session, getUILocale(), getSession().getId()); if (!removedTypes.isEmpty()) { for (ExtendedNodeType mixin : retrieveCurrentSession().getNodeByUUID(node.getUUID()) .getMixinNodeTypes()) { removedTypes.remove(mixin.getName()); } } // save properties per lang while (langCode.hasNext()) { String currentLangCode = langCode.next(); List<GWTJahiaNodeProperty> props = langCodeProperties.get(currentLangCode); session = retrieveCurrentSession(LanguageCodeConverters.languageCodeToLocale(currentLangCode)); sessions.add(session); properties.saveProperties(Arrays.asList(node), props, removedTypes, session, getUILocale(), getSession().getId()); } for (JCRSessionWrapper sessionWrapper : sessions) { sessionWrapper.validate(); } } catch (javax.jcr.nodetype.ConstraintViolationException e) { if (e instanceof CompositeConstraintViolationException) { properties.convertException((CompositeConstraintViolationException) e); } if (e instanceof NodeConstraintViolationException) { properties.convertException((NodeConstraintViolationException) e); } throw new GWTJahiaServiceException(Messages.getInternalWithArguments( "label.gwt.error.could.not.save.properties", getUILocale(), getLocalizedMessage(e))); } catch (LockException e) { logger.debug(e.getMessage(), e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments( "label.gwt.error.could.not.save.properties", getUILocale(), getLocalizedMessage(e))); } catch (RepositoryException e) { logger.error(e.getMessage(), e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments( "label.gwt.error.could.not.save.properties", getUILocale(), getLocalizedMessage(e))); } if (node.get(GWTJahiaNode.INCLUDE_CHILDREN) != null) { List<String> removedChildrenPaths = node.getRemovedChildrenPaths(); if (!removedChildrenPaths.isEmpty()) { deletePaths(removedChildrenPaths); node.clearRemovedChildrenPaths(); } List<String> newNames = new ArrayList<String>(); for (ModelData modelData : node.getChildren()) { GWTJahiaNode subNode = ((GWTJahiaNode) modelData); subNode.setPath(node.getPath() + "/" + subNode.getName()); String renamedFrom = (String) subNode.get("renamedFrom"); if (renamedFrom != null && nodeWrapper.hasNode(renamedFrom)) { // renaming sub-node first nodeWrapper.getNode(renamedFrom).rename(subNode.getName()); } newNames.add(JCRContentUtils.escapeLocalNodeName(subNode.getName())); if (subNode.get("nodeLangCodeProperties") != null && subNode.get("nodeProperties") != null) { if (nodeWrapper.hasNode(JCRContentUtils.escapeLocalNodeName(subNode.getName()))) { saveNode(subNode, null, (Map<String, List<GWTJahiaNodeProperty>>) subNode.get("nodeLangCodeProperties"), (List<GWTJahiaNodeProperty>) subNode.get("nodeProperties"), new HashSet<String>()); } else { createNode(node.getPath(), subNode); } } } if (nodeWrapper.getPrimaryNodeType().hasOrderableChildNodes()) { List<String> oldNames = new ArrayList<String>(); NodeIterator oldChildrenNodes = nodeWrapper.getNodes(); while (oldChildrenNodes.hasNext()) { JCRNodeWrapper next = (JCRNodeWrapper) oldChildrenNodes.next(); if (newNames.contains(next.getName())) { oldNames.add(next.getName()); } } if (!oldNames.equals(newNames)) { for (String newName : newNames) { nodeWrapper.orderBefore(newName, null); } } } } // save acl if (acl != null) { contentManager.setACL(node.getUUID(), acl, jcrSessionWrapper); } if (node.get("vanityMappings") != null) { saveUrlMappings(node, (Map<String, List<GWTJahiaUrlMapping>>) node.get("vanityMappings")); } if (node.get("visibilityConditions") != null) { List<GWTJahiaNode> visibilityConditions = (List<GWTJahiaNode>) node.get("visibilityConditions"); contentManager.saveVisibilityConditions(node, visibilityConditions, jcrSessionWrapper, getUILocale(), getSession().getId()); try { for (GWTJahiaNode condition : visibilityConditions) { if (Boolean.TRUE.equals(condition.get("node-published") != null)) { publication.publish( Arrays.asList(jcrSessionWrapper.getNode(condition.getPath()).getIdentifier())); } } if (Boolean.TRUE.equals(node.get("conditions-published"))) { publication.publish(Arrays.asList(jcrSessionWrapper .getNode(node.getPath() + "/" + VisibilityService.NODE_NAME).getIdentifier())); } } catch (RepositoryException e) { logger.error("Error while saving visibility conditions for node " + node.getPath(), e); throw new GWTJahiaServiceException(e); } } if (node.get("activeWorkflows") != null) { workflow.updateWorkflowRules(node, (Set<GWTJahiaWorkflowDefinition>) node.get("activeWorkflows"), jcrSessionWrapper); } GWTResourceBundle rb = node.get(GWTJahiaNode.RESOURCE_BUNDLE); boolean needPermissionReload = false; if (rb != null) { needPermissionReload = GWTResourceBundleUtils.store(node, rb, jcrSessionWrapper); } jcrSessionWrapper.save(); if (rb != null) { try { result.put(GWTJahiaNode.SITE_LANGUAGES, languages.getLanguages( (JCRSiteNode) jcrSessionWrapper.getNodeByIdentifier(node.getSiteUUID()), getLocale())); if (needPermissionReload) { // need to load the permissions result.put(GWTJahiaNode.PERMISSIONS, getAvailablePermissions()); } } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } } catch (LockException e) { throw new GWTJahiaServiceException(Messages.getInternalWithArguments("could.not.be.accessed", getUILocale(), node.getDisplayName(), getLocalizedMessage(e))); } catch (javax.jcr.nodetype.ConstraintViolationException e) { logger.debug(e.getMessage(), e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments( "label.gwt.error.node.creation.failed.cause", getUILocale(), getLocalizedMessage(e))); } catch (RepositoryException e) { logger.error(e.getMessage(), e); throw new GWTJahiaServiceException(Messages.getInternalWithArguments( "label.gwt.error.node.creation.failed.cause", getUILocale(), getLocalizedMessage(e))); } closeEditEngine(node.getPath()); return result; }
From source file:net.sourceforge.squirrel_sql.fw.dialects.DialectUtils.java
/** * Get a list of statements needed to create indexes for the specified table * /*from www. j a v a 2 s .c om*/ * @param ti * @param md * @param primaryKeys * can be null * @param prefs * @return */ public static List<String> createIndexes(ITableInfo ti, String destSimpleTableName, String destSchema, ISQLDatabaseMetaData md, List<PrimaryKeyInfo> primaryKeys, CreateScriptPreferences prefs) { if (ti == null) { throw new IllegalArgumentException("ti cannot be null"); } if (md == null) { throw new IllegalArgumentException("md cannot be null"); } final List<String> result = new ArrayList<String>(); if (ti.getDatabaseObjectType() == DatabaseObjectType.VIEW) { return result; } final List<IndexColInfo> pkCols = new ArrayList<IndexColInfo>(); if (primaryKeys != null) { for (final PrimaryKeyInfo pkInfo : primaryKeys) { pkCols.add(new IndexColInfo(pkInfo.getColumnName())); } Collections.sort(pkCols, IndexColInfo.NAME_COMPARATOR); } List<IndexInfo> indexInfos = null; try { indexInfos = md.getIndexInfo(ti); } catch (final SQLException e) { // i18n[DialectUtils.error.getprimarykey=Unable to get primary key // info for table {0}] final String msg = s_stringMgr.getString("DialectUtils.error.getprimarykey", ti.getSimpleName()); log.error(msg, e); return result; } // Group all columns by index final Hashtable<String, TableIndexInfo> buf = new Hashtable<String, TableIndexInfo>(); for (final IndexInfo indexInfo : indexInfos) { final String indexName = indexInfo.getSimpleName(); if (StringUtils.isEmpty(indexName)) { continue; } final String columnName = indexInfo.getColumnName(); if (StringUtils.isEmpty(columnName)) { continue; } final TableIndexInfo ixi = buf.get(indexName); if (null == ixi) { final List<IndexColInfo> ixCols = new ArrayList<IndexColInfo>(); ixCols.add(new IndexColInfo(columnName, indexInfo.getOrdinalPosition())); buf.put(indexName, new TableIndexInfo(indexInfo.getTableName(), indexInfo.getSchemaName(), indexName, ixCols, !indexInfo.isNonUnique())); } else { ixi.cols.add(new IndexColInfo(indexInfo.getColumnName(), indexInfo.getOrdinalPosition())); } } final TableIndexInfo[] ixs = buf.values().toArray(new TableIndexInfo[buf.size()]); for (final TableIndexInfo ix : ixs) { Collections.sort(ix.cols, IndexColInfo.NAME_COMPARATOR); if (pkCols.equals(ix.cols)) { // Serveral DBs automatically create an index for primary key // fields // and return this index in getIndexInfo(). We remove this index // from the script // because it would break the script with an index already // exists error. continue; } Collections.sort(ix.cols, IndexColInfo.ORDINAL_POSITION_COMPARATOR); final StringBuilder indexSQL = new StringBuilder(); indexSQL.append("CREATE"); indexSQL.append(ix.unique ? " UNIQUE " : " "); indexSQL.append("INDEX "); indexSQL.append(ix.ixName); indexSQL.append(" ON "); indexSQL.append(formatQualifIntern(destSimpleTableName, destSchema, prefs)); if (ix.cols.size() == 1) { indexSQL.append("(").append(ix.cols.get(0)); for (int j = 1; j < ix.cols.size(); j++) { indexSQL.append(",").append(ix.cols.get(j)); } } else { indexSQL.append("\n(\n"); for (int j = 0; j < ix.cols.size(); j++) { indexSQL.append(" "); indexSQL.append(ix.cols.get(j)); if (j < ix.cols.size() - 1) { indexSQL.append(",\n"); } else { indexSQL.append("\n"); } } } indexSQL.append(")"); result.add(indexSQL.toString()); } return result; }
From source file:ubic.gemma.core.loader.expression.geo.GeoConverterImpl.java
private void sanityCheckQuantitationTypes(List<GeoSample> datasetSamples) { List<String> reference = new ArrayList<>(); // Choose a reference that is populated ... boolean expectingData = true; for (GeoSample sample : datasetSamples) { if (sample.hasUsableData()) { reference = sample.getColumnNames(); if (!reference.isEmpty()) break; } else {// w w w. j a v a 2s . c o m expectingData = false; } } if (!expectingData) { GeoConverterImpl.log.warn("Not expecting any data, so quantitation type checking is skipped."); return; } if (reference.isEmpty()) { throw new IllegalStateException("None of the samples have any quantitation type names"); } boolean someDidntMatch = false; String lastError = ""; for (GeoSample sample : datasetSamples) { List<String> columnNames = sample.getColumnNames(); assert !columnNames.isEmpty(); if (!reference.equals(columnNames)) { StringBuilder buf = new StringBuilder(); buf.append("\nSample ").append(sample.getGeoAccession()).append(":"); for (String string : columnNames) { buf.append(" ").append(string); } buf.append("\nReference ").append(datasetSamples.iterator().next().getGeoAccession()).append(":"); for (String string : reference) { buf.append(" ").append(string); } someDidntMatch = true; lastError = "*** Sample quantitation type names do not match: " + buf.toString(); GeoConverterImpl.log.debug(lastError); } } if (someDidntMatch) { GeoConverterImpl.log .warn("Samples do not have consistent quantification type names. Last error was: " + lastError); } }