List of usage examples for java.lang Long equals
public boolean equals(Object obj)
From source file:com.evolveum.midpoint.prism.delta.ItemDelta.java
private void acceptSet(Collection<V> set, Long id, Visitor visitor, ItemPath rest, boolean recursive) { if (set == null) { return;/* w ww .j ava2 s . c o m*/ } for (V pval : set) { if (pval instanceof PrismContainerValue<?>) { PrismContainerValue<?> cval = (PrismContainerValue<?>) pval; if (id == null || id.equals(cval.getId())) { pval.accept(visitor, rest, recursive); } } else { throw new IllegalArgumentException("Attempt to fit container id to " + pval.getClass()); } } }
From source file:org.alfresco.repo.domain.permissions.AclDAOImpl.java
/** * {@inheritDoc}//w w w. j ava2s . c o m */ @Override public List<AclChange> mergeInheritedAccessControlList(Long inherited, Long target) { // TODO: For now we do a replace - we could do an insert if both inherit from the same acl List<AclChange> changes = new ArrayList<AclChange>(); Acl targetAcl = aclCrudDAO.getAcl(target); Acl inheritedAcl = null; if (inherited != null) { inheritedAcl = aclCrudDAO.getAcl(inherited); } else { // Assume we are just resetting it to inherit as before if (targetAcl.getInheritsFrom() != null) { inheritedAcl = aclCrudDAO.getAcl(targetAcl.getInheritsFrom()); if (inheritedAcl == null) { // TODO: Try previous versions throw new IllegalStateException("No old inheritance definition to use"); } else { // find the latest version of the acl if (!inheritedAcl.isLatest()) { final String searchAclId = inheritedAcl.getAclId(); Long actualInheritor = (Long) aclCrudDAO.getLatestAclByGuid(searchAclId); inheritedAcl = aclCrudDAO.getAcl(actualInheritor); if (inheritedAcl == null) { // TODO: Try previous versions throw new IllegalStateException("No ACL found"); } } } } else { // There is no inheritance to set return changes; } } // recursion test // if inherited already inherits from the target Acl test = inheritedAcl; Set<Long> visitedAcls = new HashSet<Long>(); while (test != null) { Long testId = test.getId(); if (testId != null && testId.equals(target)) { throw new IllegalStateException("Cyclical ACL detected"); } if (visitedAcls.contains(testId)) { throw new IllegalStateException("Cyclical InheritsFrom detected. AclId: " + testId); } else { visitedAcls.add(testId); } Long parent = test.getInheritsFrom(); if ((parent == null) || (parent == -1l)) { test = null; } else { test = aclCrudDAO.getAcl(test.getInheritsFrom()); } } if ((targetAcl.getAclType() != ACLType.DEFINING) && (targetAcl.getAclType() != ACLType.LAYERED)) { throw new IllegalArgumentException("Only defining ACLs can have their inheritance set"); } if (!targetAcl.getInherits()) { return changes; } Long actualInheritedId = inheritedAcl.getId(); if ((inheritedAcl.getAclType() == ACLType.DEFINING) || (inheritedAcl.getAclType() == ACLType.LAYERED)) { actualInheritedId = getInheritedAccessControlList(actualInheritedId); } // Will remove from the cache getWritable(target, actualInheritedId, null, null, actualInheritedId, true, changes, WriteMode.CHANGE_INHERITED); return changes; }
From source file:org.openmeetings.app.remote.UserService.java
/** * deletes a user//ww w. j a v a 2 s .c om * * @param SID * @param user_idClient * @return */ public Long deleteUserAdmin(String SID, Long user_idClient) { log.debug("deleteUserAdmin"); try { Long users_id = sessionManagement.checkSession(SID); Long user_level = userManagement.getUserLevelByID(users_id); // admins only if (authLevelManagement.checkAdminLevel(user_level)) { // no self destruction ;-) if (!users_id.equals(user_idClient)) { // Setting user deleted Long userId = usersDao.deleteUserID(user_idClient); return userId; } else { return new Long(-38); } } else { return new Long(-11); } } catch (Exception err) { log.error("[deleteUserAdmin]", err); } return null; }
From source file:org.geosdi.geoplatform.experimental.connector.core.OAuth2ProjectTest.java
@Test public void testSecureUpdateAccountsProjectSharingRemoveAll() throws Exception { // Insert a User to which the Project is shared as viewer Long newUserID = this.createAndInsertUser("user_to_share_oauth2_project", organizationTest, GPRole.USER); GPUser newUser = oauth2CoreClientConnector.getUserDetail(newUserID); this.createAndInsertAccountProject(newUser, projectTest, BasePermission.READ); // Set the Project as share projectTest.setShared(true);//from w w w . j a va 2 s . c o m oauth2CoreClientConnector.updateProject(projectTest); // Initial test GPProject project = oauth2CoreClientConnector.getProjectDetail(idProjectTest); Assert.assertTrue(project.isShared()); List<ShortAccountDTO> accountsToShare = oauth2CoreClientConnector.getAccountsByProjectID(idProjectTest) .getAccounts(); Assert.assertNotNull(accountsToShare); Assert.assertEquals(2, accountsToShare.size()); Assert.assertEquals(2, accountsToShare.size()); boolean check = false; for (ShortAccountDTO accountDTO : accountsToShare) { if (newUserID.equals(accountDTO.getId())) { check = true; break; } } Assert.assertTrue(check); // Test delete user for sharing boolean result = oauth2CoreClientConnector.updateAccountsProjectSharing( new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest))); Assert.assertTrue(result); project = oauth2CoreClientConnector.getProjectDetail(idProjectTest); Assert.assertFalse(project.isShared()); accountsToShare = oauth2CoreClientConnector.getAccountsByProjectID(idProjectTest).getAccounts(); Assert.assertNotNull(accountsToShare); Assert.assertEquals(1, accountsToShare.size()); Assert.assertEquals(idUserTest, accountsToShare.get(0).getId().longValue()); }
From source file:jp.primecloud.auto.service.impl.FarmServiceImpl.java
/** * {@inheritDoc}/*from w w w. j a v a 2 s. c o m*/ */ @Override public List<FarmDto> getFarms(Long userNo, Long loginUserNo) { //? User user = userDao.read(loginUserNo); //? List<Farm> farms = new ArrayList<Farm>(); // List<FarmDto> dtos = new ArrayList<FarmDto>(); //? if (user.getPowerUser()) { farms = farmDao.readAll(); for (Farm farm : farms) { FarmDto dto = new FarmDto(); dto.setFarm(farm); dtos.add(dto); } } //???? else { //?? farms = farmDao.readByUserNo(userNo); //?? List<UserAuth> userAuth = userAuthDao.readByUserNo(loginUserNo); HashMap<Long, Boolean> authMap = new HashMap<Long, Boolean>(); for (UserAuth auth : userAuth) { if (auth.getFarmUse()) { authMap.put(auth.getFarmNo(), auth.getFarmUse()); } } for (Farm farm : farms) { //????? ?? if ((loginUserNo.equals(userNo)) || authMap.containsKey(farm.getFarmNo())) { FarmDto dto = new FarmDto(); dto.setFarm(farm); dtos.add(dto); } } } // Collections.sort(dtos, Comparators.COMPARATOR_FARM_DTO); return dtos; }
From source file:com.silverpeas.servlets.upload.AjaxFileUploadServlet.java
/** * Return the current status of the upload. * * @param session the HttpSession./*from w w w .jav a2 s. co m*/ * @param response where the status is to be written. * @throws IOException */ private void doStatus(HttpSession session, HttpServletResponse response) throws IOException { boolean isSavingUploadedFiles = isSavingUploadedFile(session); Long bytesProcessed = null; Long totalSize = null; FileUploadListener.FileUploadStats fileUploadStats = (FileUploadListener.FileUploadStats) session .getAttribute(FILE_UPLOAD_STATS); if (fileUploadStats != null) { bytesProcessed = fileUploadStats.getBytesRead(); totalSize = fileUploadStats.getTotalSize(); } // Make sure the status response is not cached by the browser response.addHeader("Expires", "0"); response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); response.addHeader("Cache-Control", "post-check=0, pre-check=0"); response.addHeader("Pragma", "no-cache"); String fatalError = (String) session.getAttribute(UPLOAD_FATAL_ERROR); if (StringUtil.isDefined(fatalError)) { List<String> paths = (List<String>) session.getAttribute(FILE_UPLOAD_PATHS); String uploadedFilePaths = getUploadedFilePaths(paths); response.getWriter().println("<b>Upload uncomplete.</b>"); response.getWriter().println("<script type='text/javascript'>window.parent.stop('" + fatalError + "', " + uploadedFilePaths + "); stop('" + fatalError + "', " + uploadedFilePaths + ");</script>"); return; } if (bytesProcessed != null) { long percentComplete = (long) Math .floor((bytesProcessed.doubleValue() / totalSize.doubleValue()) * 100.0); response.getWriter().println("<b>Upload Status:</b><br/>"); if (!bytesProcessed.equals(totalSize)) { response.getWriter().println("<div class=\"prog-border\"><div class=\"prog-bar\" style=\"width: " + percentComplete + "%;\"></div></div>"); } else { response.getWriter() .println("<div class=\"prog-border\"><div class=\"prog-bar\" style=\"width: 100%;" + "\"></div></div>"); if (!isSavingUploadedFiles) { List<String> paths = (List<String>) session.getAttribute(FILE_UPLOAD_PATHS); String uploadedFilePaths = getUploadedFilePaths(paths); String errors = (String) session.getAttribute(UPLOAD_ERRORS); if (StringUtil.isDefined(errors)) { response.getWriter().println("<b>Upload complete with error(s).</b><br/>"); } else { response.getWriter().println("<b>Upload complete.</b><br/>"); errors = ""; } response.getWriter() .println("<script type='text/javascript'>window.parent.stop('" + errors + "', " + uploadedFilePaths + "); stop('" + errors + "', " + uploadedFilePaths + ");</script>"); } } } }
From source file:org.sakaiproject.lessonbuildertool.model.SimplePageToolDaoImpl.java
public boolean deleteQuestionAnswer(SimplePageQuestionAnswer questionAnswer, SimplePageItem question) { if (!canEditPage(question.getPageId())) { log.warn(//from w w w . ja v a 2 s .c o m "User tried to edit question on page without edit permission. PageId: " + question.getPageId()); return false; } // getId returns long, so this can never be null Long delid = questionAnswer.getId(); // find new id number, max + 1 // JSON uses Long for integer values List answers = (List) question.getJsonAttribute("answers"); Long max = -1L; if (answers == null) return false; for (Object a : answers) { Map answer = (Map) a; if (delid.equals(answer.get("id"))) { answers.remove(a); return true; } } return false; }
From source file:controllers.core.PortfolioEntryStatusReportingController.java
/** * Form to create/edit a risk/issue./* ww w . j a va 2 s . c o m*/ * * @param id * the portfolio entry id * @param riskId * the risk/issue id (set to 0 for create case) * @param isRisk * set to true if it's a risk, else this is an issue (this flag * is useful for the create case) */ @With(CheckPortfolioEntryExists.class) @Dynamic(IMafConstants.PORTFOLIO_ENTRY_EDIT_DYNAMIC_PERMISSION) public Result manageRisk(Long id, Long riskId, Boolean isRisk) { // get the portfolioEntry PortfolioEntry portfolioEntry = PortfolioEntryDao.getPEById(id); // initiate the form with the template Form<PortfolioEntryRiskFormData> riskForm = riskFormTemplate; // initiate the form data PortfolioEntryRiskFormData portfolioEntryRiskFormData = null; // edit case: get the portfolioEntry risk instance if (!riskId.equals(Long.valueOf(0))) { PortfolioEntryRisk portfolioEntryRisk = PortfolioEntryRiskDao.getPERiskById(riskId); // security: the portfolioEntry must be related to the object if (!portfolioEntryRisk.portfolioEntry.id.equals(id)) { return forbidden(views.html.error.access_forbidden.render("")); } isRisk = !portfolioEntryRisk.hasOccured; portfolioEntryRiskFormData = new PortfolioEntryRiskFormData(portfolioEntryRisk); } else { // create case: set default values portfolioEntryRiskFormData = new PortfolioEntryRiskFormData(); portfolioEntryRiskFormData.isActive = true; } riskForm = riskFormTemplate.fill(portfolioEntryRiskFormData); if (!riskId.equals(Long.valueOf(0))) { // add the custom attributes values this.getCustomAttributeManagerService().fillWithValues(riskForm, PortfolioEntryRisk.class, riskId); } else { // add the custom attributes default values this.getCustomAttributeManagerService().fillWithValues(riskForm, PortfolioEntryRisk.class, null); } return ok(views.html.core.portfolioentrystatusreporting.risk_manage.render(portfolioEntry, riskForm, PortfolioEntryRiskDao.getPERiskTypeActiveAsVH(), isRisk)); }
From source file:org.alfresco.repo.node.NodeServiceTest.java
@Test public void testCascadeUpdate() { NodeRef nodeRef1 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef(); assertFalse(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_CASCADE_UPDATE)); Map<QName, Serializable> aspectProps = new HashMap<QName, Serializable>(); ArrayList<NodeRef> cats = new ArrayList<NodeRef>(); cats.add(nodeRef1);/* ww w . ja v a 2 s . c o m*/ aspectProps.put(ContentModel.PROP_CATEGORIES, cats); nodeService.addAspect(nodeRef1, ContentModel.ASPECT_GEN_CLASSIFIABLE, aspectProps); assertTrue(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_GEN_CLASSIFIABLE)); assertFalse(nodeService.getAspects(nodeRef1).contains(ContentModel.ASPECT_CASCADE_UPDATE)); NodeRef nodeRef2 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef(); NodeRef nodeRef3 = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef(); NodeRef nodeRef4 = nodeService.createNode(nodeRef2, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName()), ContentModel.TYPE_CONTAINER).getChildRef(); assertFalse(nodeService.getAspects(nodeRef2).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef3).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef4).contains(ContentModel.ASPECT_CASCADE_UPDATE)); nodeService.moveNode(nodeRef4, nodeRef3, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName())); assertFalse(nodeService.getAspects(nodeRef2).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef3).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertTrue(nodeService.getAspects(nodeRef4).contains(ContentModel.ASPECT_CASCADE_UPDATE)); Status status = nodeService.getNodeStatus(nodeRef4); Long lastCascadeTx = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_TX); assertTrue(status.getDbTxnId().equals(lastCascadeTx)); assertTrue(nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC) != null); Long crcIn3 = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC); nodeService.moveNode(nodeRef4, nodeRef2, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName())); Long crcIn2 = (Long) nodeService.getProperty(nodeRef4, ContentModel.PROP_CASCADE_CRC); assertFalse(crcIn2.equals(crcIn3)); NodeRef nodeRef5 = nodeService .createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "5"), ContentModel.TYPE_CONTAINER) .getChildRef(); NodeRef nodeRef6 = nodeService .createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "6"), ContentModel.TYPE_CONTAINER) .getChildRef(); NodeRef nodeRef7 = nodeService .createNode(nodeRef5, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "7"), ContentModel.TYPE_CONTAINER) .getChildRef(); NodeRef nodeRef8 = nodeService .createNode(nodeRef5, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "8"), ContentModel.TYPE_CONTAINER) .getChildRef(); assertFalse(nodeService.getAspects(nodeRef5).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef6).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef7).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef8).contains(ContentModel.ASPECT_CASCADE_UPDATE)); nodeService.addChild(nodeRef6, nodeRef7, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName())); assertFalse(nodeService.getAspects(nodeRef5).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef6).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertTrue(nodeService.getAspects(nodeRef7).contains(ContentModel.ASPECT_CASCADE_UPDATE)); assertFalse(nodeService.getAspects(nodeRef8).contains(ContentModel.ASPECT_CASCADE_UPDATE)); Long doubleLinkCRC = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC); assertNotNull(doubleLinkCRC); nodeService.removeChild(nodeRef6, nodeRef7); Long singleLinkCRC = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC); assertFalse(doubleLinkCRC.equals(singleLinkCRC)); nodeService.addChild(nodeRef6, nodeRef7, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, this.getClass().getName())); Long doubleLinkCRC2 = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC); assertFalse(singleLinkCRC.equals(doubleLinkCRC2)); nodeService.removeChild(nodeRef6, nodeRef7); Long singleLinkCRC2 = (Long) nodeService.getProperty(nodeRef7, ContentModel.PROP_CASCADE_CRC); assertFalse(doubleLinkCRC2.equals(singleLinkCRC2)); }
From source file:gov.nih.nci.cananolab.restful.sample.SampleBO.java
/** * Save a new or existing POC with updates. * /*from w w w .jav a 2 s .c o m*/ * For Rest call: 1. Update Sample: when add POC and save are clicked * 2. Update Sample: when edit POC and save are clicked * 3. Submit Sample: when add POC and save are clicked. In this case, sample only has a name. * * Updating an existing POC with a new organization name is the equivalent of creating new and deleting old * * @param simplePOC * @param request * @return * @throws Exception */ public SampleEditGeneralBean savePointOfContact(SampleEditGeneralBean simpleSampleBean, SimplePointOfContactBean simplePOC, HttpServletRequest request) throws Exception { logger.debug("========== Start saving POC"); List<String> errors = validatePointOfContactInput(simplePOC); if (errors.size() > 0) { return wrapErrorsInEditBean(errors, "POC"); } UserBean user = (UserBean) (request.getSession().getAttribute("user")); SampleBean sample = (SampleBean) request.getSession().getAttribute("theSample"); long sampleId = simpleSampleBean.getSampleId(); String sampleName = simpleSampleBean.getSampleName(); boolean newSample = false; if (sample == null) { if (sampleName == null || sampleName.length() == 0) return this .wrapErrorInEditBean("Sample object in session is not valid for sample update operation"); else { //add poc in submit new sample workflow sample = new SampleBean(); sample.getDomain().setName(sampleName); newSample = true; } } else if (sampleId <= 0) { sample.getDomain().setName(sampleName); newSample = true; } else { if (sample.getDomain().getId() != sampleId) return this.wrapErrorInEditBean("Current sample id doesn't match sample id in session"); } logger.debug("========== Resolving Input"); PointOfContactBean thePOC = resolveThePOCToSaveFromInput(sample, simplePOC, user.getLoginName()); Long oldPOCId = thePOC.getDomain().getId(); determinePrimaryPOC(thePOC, sample, newSample); // set up one sampleService SampleService service = setServiceInSession(request); // have to save POC separately because the same organizations can not be // saved in the same session service.savePointOfContact(thePOC); sample.addPointOfContact(thePOC, oldPOCId); logger.debug("========== Done saving POC"); // if the oldPOCId is different from the one after POC save if (oldPOCId != null && !oldPOCId.equals(thePOC.getDomain().getId())) { // update characterization POC associations ((SampleServiceLocalImpl) service).updatePOCAssociatedWithCharacterizations( sample.getDomain().getName(), oldPOCId, thePOC.getDomain().getId()); } try { // save sample logger.debug("========== Saving Sample with POC"); saveSample(request, sample); logger.debug("========== Done Saving Sample with POC"); } catch (NoAccessException e) { if (newSample) simpleSampleBean.getPointOfContacts().clear(); request.getSession().setAttribute("theSample", sample); simpleSampleBean.getErrors().add("User has no access to edit this sample"); simpleSampleBean.transferPointOfContactData(sample); ; return simpleSampleBean; } catch (DuplicateEntriesException e) { if (newSample) simpleSampleBean.getPointOfContacts().clear(); request.getSession().setAttribute("theSample", sample); simpleSampleBean.getErrors().add(PropertyUtil.getProperty("sample", "error.duplicateSample")); simpleSampleBean.transferPointOfContactData(sample); ; return simpleSampleBean; //return this.wrapErrorInEditBean(PropertyUtil.getProperty("sample", "error.duplicateSample")); } catch (Exception e) { if (newSample) simpleSampleBean.getPointOfContacts().clear(); request.getSession().setAttribute("theSample", sample); simpleSampleBean.getErrors().add(e.getMessage()); simpleSampleBean.transferPointOfContactData(sample); ; return simpleSampleBean; } //logger.debug("========== Done saving POC Sample"); //if (newSample != null && newSampleName.length() > 0) if (newSample) { logger.debug("========== Setting access for new sample"); this.setAccesses(request, sample); //this will assign default curator access to this sample. logger.debug("========== Done Setting access for new sample"); } //This is needed when user chose "[other]" in Org. Name dropdown InitSampleSetup.getInstance().persistPOCDropdowns(request, sample); logger.debug("========== Populating UpdateSample data"); return summaryEdit(sample.getDomain().getId().toString(), request); }