List of usage examples for java.lang Long equals
public boolean equals(Object obj)
From source file:ome.services.ThumbnailCtx.java
/** * Checks to see if a thumbnail is in the on disk cache or not. * //from ww w . j a v a 2 s. c o m * @param pixelsId The Pixels set the thumbnail is for. * @return Whether or not the thumbnail is in the on disk cache. */ public boolean isThumbnailCached(long pixelsId) { Thumbnail metadata = pixelsIdMetadataMap.get(pixelsId); try { boolean dirtyMetadata = dirtyMetadata(pixelsId); boolean thumbnailExists = thumbnailService.getThumbnailExists(metadata); boolean isExtendedGraphCritical = isExtendedGraphCritical(Collections.singleton(pixelsId)); Long metadataOwnerId = metadata.getDetails().getOwner().getId(); Long sessionUserId = getCurrentUserId(); boolean isMyMetadata = sessionUserId.equals(metadataOwnerId); if (!dirtyMetadata) { if (thumbnailExists) { return true; } else if (!thumbnailExists && isExtendedGraphCritical) { throw new ResourceError(String.format("Error retrieving Pixels id:%d. Thumbnail " + "metadata exists but a thumbnail is not " + "available in the cache. User id:%d has " + "insufficient permissions to create it.", pixelsId, userId)); } } else if (thumbnailExists && !isMyMetadata) { log.warn(String.format( "Thumbnail metadata is dirty for Pixels Id:%d and " + "the metadata is owned User id:%d which is not us " + "User id:%d. Ignoring this and returning the cached " + "thumbnail.", pixelsId, metadataOwnerId, sessionUserId)); return true; } else if (thumbnailExists && isExtendedGraphCritical) { log.warn(String.format("Thumbnail metadata is dirty for Pixels Id:%d and " + "graph is critical for User id:%d. Ignoring this " + "and returning the cached thumbnail.", pixelsId, userId)); return true; } } catch (IOException e) { String s = "Could not check if thumbnail is cached: "; log.error(s, e); throw new ResourceError(s + e.getMessage()); } return false; }
From source file:com.granita.tasks.TaskListFragment.java
/** Returns the position of the task in the cursor. Returns -1 if the task is not in the cursor **/ private int getSelectedChildPostion(Uri taskUri, Cursor listCursor) { if (taskUri != null && listCursor != null && listCursor.moveToFirst()) { Long taskIdToSelect = Long.valueOf(taskUri.getLastPathSegment()); do {/*from w w w. jav a 2 s .co m*/ Long taskId = listCursor.getLong(listCursor.getColumnIndex(Tasks._ID)); if (taskId.equals(taskIdToSelect)) { return listCursor.getPosition(); } } while (listCursor.moveToNext()); } return -1; }
From source file:edu.ur.hibernate.ir.file.db.VersionedFileDAOTest.java
/** * Test add a file to an irFile/*from www.ja v a 2s . com*/ * @throws LocationAlreadyExistsException */ @Test public void versionedFileAddMultiFileDAOTest() throws IllegalFileSystemNameException, LocationAlreadyExistsException { cleanDirectory(); TransactionStatus ts = tm.getTransaction(td); // create a repository to store files in. RepositoryBasedTestHelper repoHelper = new RepositoryBasedTestHelper(ctx); Repository repo = repoHelper.createRepository("localFileServer", "displayName", "file_database", "my_repository", properties.getProperty("a_repo_path"), "default_folder"); // save the repository tm.commit(ts); // Start the transaction ts = tm.getTransaction(td); // create the first file to store in the temporary folder String tempDirectory = properties.getProperty("ir_hibernate_temp_directory"); File directory = new File(tempDirectory); // helper to create the file FileUtil testUtil = new FileUtil(); testUtil.createDirectory(directory); File f = testUtil.creatFile(directory, "testFile", "Hello - irFile This is text in a file - VersionedFileDAO test"); long fileSize1 = f.length(); assert fileSize1 > 0 : "File size shold be greater than 0"; long totalSize = fileSize1; // create the file in the file system. FileInfo fileInfo1 = repo.getFileDatabase().addFile(f, "newFile1"); fileInfo1.setDisplayName("displayName1"); // add a second file File f2 = testUtil.creatFile(directory, "testFile2", "Hello2 - irFile This is text in second file - VersionedFileDAO test"); // create the file in the file system. FileInfo fileInfo2 = repo.getFileDatabase().addFile(f2, "newFile2"); fileInfo2.setDisplayName("displayName2"); long fileSize2 = f2.length(); assert fileSize2 > 0 : "File 2 size shold be greater than 0"; totalSize += fileSize2; assert totalSize == (fileSize1 + fileSize2) : "total size should equal " + fileSize1 + " + " + fileSize2 + " but equals " + totalSize; UserEmail userEmail = new UserEmail("email"); IrUser user = new IrUser("user", "password"); user.setPasswordEncoding("encoding"); user.addUserEmail(userEmail, true); userDAO.makePersistent(user); // create the versioned file VersionedFile vif = new VersionedFile(user, fileInfo1, "new file test"); // add the second version of the file vif.addNewVersion(fileInfo2, user); versionedIrFileDAO.makePersistent(vif); tm.commit(ts); // Start the transaction ts = tm.getTransaction(td); VersionedFile otherVf = versionedIrFileDAO.getById(vif.getId(), false); Long irFileId1 = vif.getVersion(1).getIrFile().getId(); Long irFileId2 = vif.getCurrentVersion().getIrFile().getId(); assert irFileId1 != null : "File id should not be equal to null"; assert irFileId1 > 0 : "File id should be greater than 0 "; assert irFileId2 != null : "File id should not be equal to null"; assert irFileId2 > 0 : "File id should be greater than 0 "; assert !irFileId1.equals(irFileId2) : "file ids should be different but are not"; assert vif.getLargestVersion() == 2 : "Current version should be 2 but is " + vif.getLargestVersion(); // make sure file size is correct assert otherVf.getCurrentFileSizeBytes() == fileSize2 : " current version file size " + " should be " + fileSize2 + " but is " + otherVf.getCurrentFileSizeBytes(); assert otherVf.getTotalSizeForAllFilesBytes() == totalSize : " Total size is " + totalSize + " and get total size = " + otherVf.getTotalSizeForAllFilesBytes(); tm.commit(ts); // Test rename // Start the transaction ts = tm.getTransaction(td); otherVf = versionedIrFileDAO.getById(vif.getId(), false); otherVf.reName("fileName4.doc"); versionedIrFileDAO.makePersistent(otherVf); tm.commit(ts); /* * Test versioned file and delete versioned file and user */ // Start the transaction ts = tm.getTransaction(td); VersionedFile other = versionedIrFileDAO.getById(vif.getId(), false); assert other != null : "Other should not be null"; // make sure name changes where saved assert other.getNameWithExtension() .equals("fileName4.doc") : "Name with extension should be fileName4.doc but is: " + other.getNameWithExtension(); assert other.getName().equals("fileName4") : "Name should be fileName4 but is : " + other.getName(); assert other.getCurrentVersion().getIrFile().getName() .equals("fileName4") : "Name with extension should be fileName4 but is: " + other.getCurrentVersion().getIrFile().getName(); assert other.getCurrentVersion().getIrFile().getFileInfo().getExtension() .equals("doc") : "extension should be .doc but is: " + other.getCurrentVersion().getIrFile().getFileInfo().getExtension(); versionedIrFileDAO.makeTransient(other); fileDAO.makeTransient(fileDAO.getById(irFileId1, false)); fileDAO.makeTransient(fileDAO.getById(irFileId2, false)); userDAO.makeTransient(userDAO.getById(user.getId(), false)); repoHelper.cleanUpRepository(); tm.commit(ts); }
From source file:com.flyhz.avengers.framework.application.AnalyzeApplication.java
private void analyze() { LOG.info("initanalyze first ......"); HConnection hConnection = null;/*from w w w .j a v a 2 s . c o m*/ HBaseAdmin hbaseAdmin = null; // HTable hVersion = null; HTable hPage = null; try { hConnection = HConnectionManager.createConnection(hbaseConf); hbaseAdmin = new HBaseAdmin(hConnection); Configuration configuration = HBaseConfiguration.create(hbaseConf); configuration.setLong("hbase.rpc.timeout", 600000); // Scan configuration.setLong("hbase.client.scanner.caching", 1000); hPage = new HTable(hbaseConf, AVTable.av_page.name()); Scan scan = new Scan(); scan.addColumn(Bytes.toBytes(AVFamily.i.name()), Bytes.toBytes(AVColumn.bid.name())); ResultScanner rs = hPage.getScanner(scan); for (Result result : rs) { for (Cell cell : result.rawCells()) { String url = Bytes.toString(cell.getRowArray()); String family = Bytes.toString(cell.getFamilyArray()); String column = Bytes.toString(cell.getQualifierArray()); Long value = Bytes.toLong(cell.getValueArray()); LOG.info("rowkey -> {},family -> {},column -> {},value ->{}", url, family, column, value); if ("preference".equals(family) && "batchId".equals(column) && value.equals(this.batchId)) { urls.add(url); } if (urls.size() == 100) { this.numTotalContainers = 100; for (int i = 0; i < numTotalContainers; ++i) { ContainerRequest containerAsk = setupContainerAskForRM(); amRMClient.addContainerRequest(containerAsk); } numRequestedContainers.set(numTotalContainers); while (!done && (numCompletedContainers.get() != numTotalContainers)) { try { Thread.sleep(200); } catch (InterruptedException ex) { } } } } } } catch (IOException e) { LOG.error("analyze", e); } catch (Throwable e) { LOG.error("analyze", e); } finally { if (hPage != null) { try { hPage.close(); } catch (IOException e) { LOG.error("", e); } } if (hbaseAdmin != null) { try { hbaseAdmin.close(); } catch (IOException e) { LOG.error("", e); } } if (hConnection != null) { try { hConnection.close(); } catch (IOException e) { LOG.error("", e); } } } }
From source file:jp.primecloud.auto.component.mysql.process.MySQLPuppetComponentProcess.java
@Override @SuppressWarnings("unchecked") protected Map<String, Object> createInstanceMap(Long componentNo, ComponentProcessContext context, boolean start, Long instanceNo, Map<String, Object> rootMap) { Map<String, Object> map = super.createInstanceMap(componentNo, context, start, instanceNo, rootMap); // Master??Slave???????? Map<Long, Long> masterInstanceNoMap = (Map<Long, Long>) rootMap.get("masterInstanceNoMap"); Long masterInstanceNo = masterInstanceNoMap.get(instanceNo); if (masterInstanceNo == null) { // Master??? map.put("mysqlType", "MASTER"); // Slave?Instances List<Instance> slaveInstances = new ArrayList<Instance>(); for (Entry<Long, Long> entry : masterInstanceNoMap.entrySet()) { if (instanceNo.equals(entry.getValue())) { Instance instance = instanceDao.read(entry.getKey()); slaveInstances.add(instance); }//from w w w. j av a 2s .c om } map.put("slaveInstances", slaveInstances); } else { // Slave??? map.put("mysqlType", "SLAVE"); map.put("masterInstanceNo", masterInstanceNo); // Master?Instance ComponentInstance master = componentInstanceDao.read(componentNo, masterInstanceNo); if (master != null && ComponentInstanceStatus.fromStatus(master.getStatus()) == ComponentInstanceStatus.RUNNING) { Instance masterInstance = instanceDao.read(masterInstanceNo); map.put("masterInstance", masterInstance); } } return map; }
From source file:core.dao.PagesDAOHibernate.java
@Override @Transactional(readOnly = true)// w w w . ja v a 2 s . c o m public boolean checkRecursion(Long id, Long newIdPages) { if (id == null) { return false; } if (newIdPages == null) { return true; } //forming hql---------------------------------------------------- StringBuilder baseHQL = new StringBuilder("SELECT pages.id FROM "); baseHQL.append(this.entityName); baseHQL.append(" WHERE id = :id"); String hql = baseHQL.toString(); baseHQL = null; //--------------------------------------------------------------- Session sess = this.getSessionFactory().getCurrentSession(); Object cur_id = newIdPages; while (cur_id != null) { if (id.equals(cur_id)) { return false; } cur_id = sess.createQuery(hql).setParameter("id", cur_id).uniqueResult(); } return true; }
From source file:org.alfresco.repo.domain.permissions.ADMAccessControlListDAO.java
private CounterSet fixOldDmAcls(Long nodeId, Long existingNodeAclId, Long inheritedAclId, boolean isRoot) { CounterSet result = new CounterSet(); // If existingNodeAclId is not null and equal to inheritedAclId then we know we have hit a shared ACL we have bulk set // - just carry on in this case - we do not need to get the acl Long newDefiningAcl = null;//from w ww . j a v a 2 s. c o m if ((existingNodeAclId != null) && (existingNodeAclId.equals(inheritedAclId))) { // nothing to do except move into the children } else { AccessControlList existing = null; if (existingNodeAclId != null) { existing = aclDaoComponent.getAccessControlList(existingNodeAclId); } if (existing != null) { if (existing.getProperties().getAclType() == ACLType.OLD) { result.increment(ACLType.DEFINING); SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties( aclDaoComponent.getDefaultProperties()); properties.setInherits(existing.getProperties().getInherits()); Long actuallyInherited = null; if (existing.getProperties().getInherits()) { if (inheritedAclId != null) { actuallyInherited = inheritedAclId; } } Acl newAcl = aclDaoComponent.createAccessControlList(properties, existing.getEntries(), actuallyInherited); newDefiningAcl = newAcl.getId(); nodeDAO.setNodeAclId(nodeId, newDefiningAcl); } else if (existing.getProperties().getAclType() == ACLType.SHARED) { // nothing to do just cascade into the children - we most likely did a bulk set above. // TODO: Check shared ACL set is correct } else { // Already fixed up // TODO: Keep going to check // Check inheritance is correct return result; } } else { // Set default ACL on roots with no settings if (isRoot) { result.increment(ACLType.DEFINING); AccessControlListProperties properties = aclDaoComponent.getDefaultProperties(); Acl newAcl = aclDaoComponent.createAccessControlList(properties); newDefiningAcl = newAcl.getId(); nodeDAO.setNodeAclId(nodeId, newDefiningAcl); } else { // Unset - simple inherit nodeDAO.setNodeAclId(nodeId, inheritedAclId); } } } Long toInherit = null; List<NodeIdAndAclId> children = nodeDAO.getPrimaryChildrenAcls(nodeId); if (children.size() > 0) { // Only make inherited if required if (newDefiningAcl == null) { toInherit = inheritedAclId; } else { toInherit = aclDaoComponent.getInheritedAccessControlList(newDefiningAcl); } } if (children.size() > 0) { nodeDAO.setPrimaryChildrenSharedAclId(nodeId, null, toInherit); } for (NodeIdAndAclId child : children) { CounterSet update = fixOldDmAcls(child.getId(), child.getAclId(), toInherit, false); result.add(update); } return result; }
From source file:csns.web.controller.SiteBlockControllerS.java
@RequestMapping(value = "/site/{qtr}/{cc}-{sn}/block/editItem", method = RequestMethod.POST) public String editItem(@PathVariable String qtr, @PathVariable String cc, @PathVariable int sn, @ModelAttribute Block block, @RequestParam Long newBlockId, @ModelAttribute Item item, @RequestParam(value = "uploadedFile", required = false) MultipartFile uploadedFile, BindingResult bindingResult, SessionStatus sessionStatus) { itemValidator.validate(item, uploadedFile, bindingResult); if (bindingResult.hasErrors()) return "site/block/editItem"; User user = SecurityUtils.getUser(); Resource resource = item.getResource(); if (resource.getType() == ResourceType.FILE && uploadedFile != null && !uploadedFile.isEmpty()) resource.setFile(fileIO.save(uploadedFile, user, true)); if (newBlockId.equals(block.getId())) block = blockDao.saveBlock(block); else {/* w w w. j a v a 2 s . com*/ block.removeItem(item.getId()); block = blockDao.saveBlock(block); Block newBlock = blockDao.getBlock(newBlockId); newBlock.getItems().add(item); newBlock = blockDao.saveBlock(newBlock); } sessionStatus.setComplete(); logger.info(user.getUsername() + " edited item " + item.getId() + " in block " + block.getId()); return "redirect:list"; }
From source file:io.plaidapp.designernews.ui.story.StoryActivity.java
private boolean isOP(Long userId) { return userId.equals(story.getUserId()); }
From source file:org.zilverline.service.CollectionManagerImpl.java
/** * Gets a collection by id./* ww w.ja v a 2 s . c om*/ * * @param theId The id of the collection * * @return Collection or null if not found */ public DocumentCollection getCollection(final Long theId) { Iterator li = collections.iterator(); while (li.hasNext()) { DocumentCollection c = (DocumentCollection) li.next(); if (theId.equals(c.getId())) { return c; } } return null; }