List of usage examples for org.apache.commons.lang.mutable MutableInt setValue
public void setValue(Object value)
From source file:com.novartis.pcs.ontology.service.parser.obo.SynonymTagHandler.java
@Override void handleTagValue(String tag, String value, String qualifierBlock, String comment) { MutableInt fromIndex = new MutableInt(); String synonym = substr(value, '"', '"', fromIndex); if (synonym == null) { throw new InvalidFormatException("Invalid OBO synonym tag (missing quotes): " + value); }//from w w w .j av a2 s .co m synonym = context.unescapeTagValue(synonym); Synonym.Type type = parseType(value, fromIndex); String xrefList = substr(value, '[', ']', fromIndex); if (xrefList != null && xrefList.length() > 0) { List<String> xrefs = split(xrefList, ','); for (String xref : xrefs) { int colon = indexOf(xref, ':', 0); if (colon == -1) { throw new InvalidFormatException("Invalid OBO synonym xref (no datasource): " + xref); } String datasource = xref.substring(0, colon); int quote = indexOf(xref, '"', colon + 1); String refId = quote == -1 ? xref.substring(colon + 1) : xref.substring(colon + 1, quote); datasource = context.unescapeTagValue(datasource); refId = context.unescapeTagValue(refId); Synonym synonymObj = null; if (UrlParser.isValidProtocol(datasource)) { String url = datasource + ":" + refId; synonymObj = context.addSynonym(synonym, type, url); } else { synonymObj = context.addSynonym(synonym, type, datasource, refId); } if (quote != -1) { fromIndex.setValue(quote); String description = substr(xref, '"', '"', fromIndex); description = context.unescapeTagValue(description); synonymObj.setDescription(description); } } } else { context.addSynonym(synonym, type); } }
From source file:com.novartis.pcs.ontology.service.parser.obo.DefTagHandler.java
@Override void handleTagValue(String tag, String value, String qualifierBlock, String comment) { MutableInt fromIndex = new MutableInt(); String definition = substr(value, '"', '"', fromIndex); if (definition == null) { throw new InvalidFormatException("Invalid OBO def tag (missing quotes): " + value); }//from w ww . java2 s. c o m definition = context.unescapeTagValue(definition); VersionedEntity entity = context.getCurrentEntity(); if (entity instanceof Term) { Term term = (Term) entity; term.setDefinition(definition); String xrefList = substr(value, '[', ']', fromIndex); if (xrefList != null) { List<String> xrefs = split(xrefList, ','); for (String xref : xrefs) { int colon = indexOf(xref, ':', 0); if (colon == -1) { throw new InvalidFormatException("Invalid OBO xref (no datasource): " + xref); } String datasourceAcronym = xref.substring(0, colon); int quote = indexOf(xref, '"', colon + 1); String refId = quote == -1 ? xref.substring(colon + 1) : xref.substring(colon + 1, quote); datasourceAcronym = context.unescapeTagValue(datasourceAcronym); refId = context.unescapeTagValue(refId); CrossReference defXref = null; if (UrlParser.isValidProtocol(datasourceAcronym)) { String url = datasourceAcronym + ":" + refId; defXref = addCrossReference(url, true); } else { defXref = addCrossReference(datasourceAcronym, refId, true); } if (quote != -1) { fromIndex.setValue(quote); String description = substr(xref, '"', '"', fromIndex); description = context.unescapeTagValue(description); defXref.setDescription(description); } } } } else if (entity instanceof RelationshipType) { RelationshipType relationshipType = (RelationshipType) entity; relationshipType.setDefintion(definition); } }
From source file:forseti.JUtil.java
public static synchronized void getReporteFiltroProps(String str, MutableInt propMin, MutableInt propMax) { int index = str.indexOf('{'); if (index == -1) return;/*w w w .ja v a 2 s .co m*/ int indfin = str.indexOf('}'); if (indfin == -1) return; int comaind = str.indexOf(','); if (comaind == -1) return; String min = str.substring((index + 1), comaind); String max = str.substring((comaind + 1), indfin); propMin.setValue(Integer.parseInt(min)); propMax.setValue(Integer.parseInt(max)); }
From source file:nl.strohalm.cyclos.dao.accounts.fee.account.MemberAccountFeeLogDAOImpl.java
@Override public int prepareCharge(final AccountFeeLog log) { final Long[] groupIds = EntityHelper.toIds(log.getAccountFee().getGroups()); if (ArrayUtils.isEmpty(groupIds)) { // No groups to charge return 0; }/*from ww w . j a v a 2 s . c o m*/ final MutableInt result = new MutableInt(); runNative(new JDBCCallback() { @Override public void execute(final JDBCWrapper jdbc) throws SQLException { String[] placeHolders = new String[groupIds.length]; Arrays.fill(placeHolders, "?"); StringBuilder sql = new StringBuilder(); sql.append(" insert into members_pending_charge"); sql.append(" (account_fee_log_id, member_id)"); sql.append(" select ?, id"); sql.append(" from members m"); sql.append(" where m.subclass = ?"); sql.append(" and m.group_id in (").append(StringUtils.join(placeHolders, ",")).append(')'); List<Object> args = new ArrayList<Object>(groupIds.length + 2); args.add(log.getId()); args.add("M"); CollectionUtils.addAll(args, groupIds); int totalMembers = jdbc.execute(sql.toString(), args.toArray()); result.setValue(totalMembers); } }); return result.intValue(); }
From source file:org.alfresco.repo.attributes.AttributeServiceTest.java
/** * Checks that {@link AttributeService#getAttributes(AttributeQueryCallback, Serializable...) AttributeService.getAttributes} * works. This includes coverage of <a href=https://issues.alfresco.com/jira/browse/MNT-9112>MNT-9112</a>. *//* w w w.j a va2 s . com*/ public void testGetAttributes() throws Exception { attributeService.setAttribute(VALUE_AAA_STRING, KEY_AAA); attributeService.setAttribute(VALUE_AAB_STRING, KEY_AAB); attributeService.setAttribute(VALUE_AAC_STRING, KEY_AAC); final List<Serializable> results = new ArrayList<Serializable>(); final MutableInt counter = new MutableInt(); final MutableInt max = new MutableInt(3); AttributeQueryCallback callback = new AttributeQueryCallback() { @Override public boolean handleAttribute(Long id, Serializable value, Serializable[] keys) { counter.increment(); results.add(value); if (counter.intValue() == max.intValue()) { return false; } else { return true; } } }; counter.setValue(0); max.setValue(3); results.clear(); attributeService.getAttributes(callback, KEY_A); assertEquals(3, results.size()); assertEquals(3, counter.getValue()); counter.setValue(0); max.setValue(2); results.clear(); attributeService.getAttributes(callback, KEY_A); assertEquals(2, results.size()); assertEquals(2, counter.getValue()); }
From source file:org.alfresco.repo.audit.AuditComponentTest.java
public void testQuery_Action01() throws Exception { final Long beforeTime = new Long(System.currentTimeMillis()); // Make sure that we have something to search for testAudit_Action01();/*from w ww . j a va 2 s . com*/ final StringBuilder sb = new StringBuilder(); final MutableInt rowCount = new MutableInt(); AuditQueryCallback callback = new AuditQueryCallback() { public boolean valuesRequired() { return true; } public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) { assertNotNull(applicationName); assertNotNull(user); sb.append("Row: ").append(entryId).append(" | ").append(applicationName).append(" | ").append(user) .append(" | ").append(new Date(time)).append(" | ").append(values).append(" | ") .append("\n"); ; rowCount.setValue(rowCount.intValue() + 1); return true; } public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) { throw new AlfrescoRuntimeException(errorMsg, error); } }; AuditQueryParameters params = new AuditQueryParameters(); params.setForward(true); params.setApplicationName(APPLICATION_ACTIONS_TEST); sb.delete(0, sb.length()); rowCount.setValue(0); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); assertTrue("Expected some data", rowCount.intValue() > 0); logger.debug(sb.toString()); int allResults = rowCount.intValue(); // Limit by count sb.delete(0, sb.length()); rowCount.setValue(0); auditComponent.auditQuery(callback, params, 1); assertEquals("Expected to limit data", 1, rowCount.intValue()); logger.debug(sb.toString()); // Limit by time and query up to and excluding the 'before' time sb.delete(0, sb.length()); rowCount.setValue(0); params.setToTime(beforeTime); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); params.setToTime(null); logger.debug(sb.toString()); int resultsBefore = rowCount.intValue(); // Limit by time and query from and including the 'before' time sb.delete(0, sb.length()); rowCount.setValue(0); params.setFromTime(beforeTime); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); params.setFromTime(null); logger.debug(sb.toString()); int resultsAfter = rowCount.intValue(); assertEquals("Time-limited queries did not get all results before and after a time", allResults, (resultsBefore + resultsAfter)); sb.delete(0, sb.length()); rowCount.setValue(0); params.setUser(user); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); params.setUser(null); assertTrue("Expected some data for specific user", rowCount.intValue() > 0); logger.debug(sb.toString()); sb.delete(0, sb.length()); rowCount.setValue(0); params.setUser("Numpty"); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); params.setUser(null); assertTrue("Expected no data for bogus user", rowCount.intValue() == 0); logger.debug(sb.toString()); }
From source file:org.alfresco.repo.audit.AuditMethodInterceptorTest.java
/** * Test for <a href="https://issues.alfresco.com/jira/browse/MNT-11072">MNT-11072</a> <br> * Use NodeService, as it is wrapped by the AuditMethodInterceptor, to get node props in read-only server mode. * //w w w . java 2 s.c o m * @throws Exception */ public void testAuditInReadOnly() throws Exception { // Run as admin AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); QName veto = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "TestVeto"); transactionServiceImpl.setAllowWrite(false, veto); try { // Access the node in read-only transaction Map<QName, Serializable> props = transactionService.getRetryingTransactionHelper() .doInTransaction(new RetryingTransactionCallback<Map<QName, Serializable>>() { @Override public Map<QName, Serializable> execute() throws Throwable { return nodeService.getProperties(nodeRef); } }, true, false); assertNotNull("The props should exsist.", props); // Search for audit final StringBuilder sb = new StringBuilder(); final MutableInt rowCount = new MutableInt(); AuditQueryCallback callback = new AuditQueryCallback() { @Override public boolean valuesRequired() { return true; } @Override public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) { assertNotNull(applicationName); assertNotNull(user); sb.append("Row: ").append(entryId).append(" | ").append(applicationName).append(" | ") .append(user).append(" | ").append(new Date(time)).append(" | ").append(values) .append(" | ").append("\n"); rowCount.setValue(rowCount.intValue() + 1); return true; } @Override public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) { throw new AlfrescoRuntimeException(errorMsg, error); } }; AuditQueryParameters params = new AuditQueryParameters(); params.setForward(true); params.setUser(AuthenticationUtil.getAdminUserName()); params.setApplicationName(APPLICATION_NAME); rowCount.setValue(0); auditComponent.auditQuery(callback, params, Integer.MAX_VALUE); assertEquals("There should be one audit entry.", 1, rowCount.intValue()); assertTrue("The requested nodeRef should be in the audit entry.", sb.toString().contains(nodeRef.toString())); if (logger.isDebugEnabled()) { logger.debug(sb.toString()); } } finally { transactionServiceImpl.setAllowWrite(true, veto); } }
From source file:org.alfresco.repo.content.cleanup.ContentStoreCleanerScalabilityRunner.java
private void loadData(final int maxCount) { final MutableInt doneCount = new MutableInt(0); // Batches of 1000 objects RetryingTransactionCallback<Integer> makeNodesCallback = new RetryingTransactionCallback<Integer>() { public Integer execute() throws Throwable { for (int i = 0; i < 1000; i++) { // We don't need to write anything String contentUrl = FileContentStore.createNewFileStoreUrl(); ContentData contentData = new ContentData(contentUrl, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10, "UTF-8"); nodeHelper.makeNode(contentData); int count = doneCount.intValue(); count++;/*from w ww.j av a2 s . c o m*/ doneCount.setValue(count); // Do some reporting if (count % 1000 == 0) { System.out.println(String.format(" " + (new Date()) + "Total created: %6d", count)); } // Double check for shutdown if (vmShutdownListener.isVmShuttingDown()) { break; } } return maxCount; } }; int repetitions = (int) Math.floor((double) maxCount / 1000.0); for (int i = 0; i < repetitions; i++) { transactionService.getRetryingTransactionHelper().doInTransaction(makeNodesCallback); } }
From source file:org.alfresco.repo.domain.audit.AuditDAOTest.java
public synchronized void testAuditQuery() throws Exception { // Some entries doAuditEntryImpl(1);/*from ww w . j a v a 2s . c om*/ final MutableInt count = new MutableInt(0); final LinkedList<Long> timestamps = new LinkedList<Long>(); // Find everything, but look for a specific key final AuditQueryCallback callback = new AuditQueryCallback() { public boolean valuesRequired() { return false; } public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) { count.setValue(count.intValue() + 1); timestamps.add(time); return true; } public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) { throw new AlfrescoRuntimeException(errorMsg, error); } }; final AuditQueryParameters params = new AuditQueryParameters(); params.addSearchKey("/a/b/c", null); RetryingTransactionCallback<Void> findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; count.setValue(0); timestamps.clear(); txnHelper.doInTransaction(findCallback); assertTrue("Expected at least one result", count.intValue() > 0); // // Make sure that the last two entries are in forward order (ascending time) // Long lastTimestamp = timestamps.removeLast(); // Long secondLastTimeStamp = timestamps.removeLast(); // assertTrue("The timestamps should be in ascending order", lastTimestamp.compareTo(secondLastTimeStamp) > 0); // // Make sure that the last two entries differ in time wait(1000L); // Search in reverse order doAuditEntryImpl(1); RetryingTransactionCallback<Void> findReverseCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { params.setForward(false); auditDAO.findAuditEntries(callback, params, 2); params.setForward(true); return null; } }; timestamps.clear(); txnHelper.doInTransaction(findReverseCallback); // // // Make sure that the last two entries are in reverse order (descending time) // lastTimestamp = timestamps.removeLast(); // secondLastTimeStamp = timestamps.removeLast(); // assertTrue("The timestamps should be in descending order", lastTimestamp.compareTo(secondLastTimeStamp) < 0); }
From source file:org.alfresco.repo.domain.audit.AuditDAOTest.java
public synchronized void testAuditQueryCombos() throws Exception { // Some entries doAuditEntryImpl(10);//w ww . ja va 2 s. co m final MutableInt count = new MutableInt(0); final LinkedList<Long> timestamps = new LinkedList<Long>(); final List<Long> entryIds = new LinkedList<>(); // Find everything final AuditQueryCallback callback = new AuditQueryCallback() { public boolean valuesRequired() { return false; } public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) { count.setValue(count.intValue() + 1); timestamps.add(time); entryIds.add(entryId); return true; } public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) { throw new AlfrescoRuntimeException(errorMsg, error); } }; final AuditQueryParameters params = new AuditQueryParameters(); params.addSearchKey("/a/b/c", null); //. get them all RetryingTransactionCallback<Void> findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 10); return null; } }; count.setValue(0); timestamps.clear(); txnHelper.doInTransaction(findCallback); assertEquals(10, count.intValue()); // copy what we found so that we can compare subsequent audit queries List<Long> allEntryIds = new ArrayList<>(entryIds); List<Long> allTimestamps = new ArrayList<>(timestamps); // test fromId and maxResults entryIds.clear(); timestamps.clear(); params.setFromId(allEntryIds.get(2)); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allEntryIds.subList(2, 2 + 2).equals(entryIds)); // test toId and maxResults entryIds.clear(); timestamps.clear(); params.setFromId(null); params.setFromTime(null); params.setToTime(null); params.setToId(allEntryIds.get(2)); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allEntryIds.subList(0, 2).equals(entryIds)); // test fromId and toId and maxResults entryIds.clear(); timestamps.clear(); params.setFromId(allEntryIds.get(2)); params.setToId(allEntryIds.get(5)); params.setFromTime(null); params.setToTime(null); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 1); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allEntryIds.subList(2, 3).equals(entryIds)); // test fromTime and maxResults entryIds.clear(); timestamps.clear(); params.setFromTime(allTimestamps.get(2)); params.setFromId(null); params.setToTime(null); params.setToId(null); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allTimestamps.subList(2, 4).equals(timestamps)); // test toTime and maxResults entryIds.clear(); timestamps.clear(); params.setFromTime(null); params.setFromId(null); params.setToTime(allTimestamps.get(4)); params.setToId(null); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allTimestamps.subList(0, 2).equals(timestamps)); // test fromTime and toTime and maxResults entryIds.clear(); timestamps.clear(); params.setFromTime(allTimestamps.get(2)); params.setFromId(null); params.setToTime(allTimestamps.get(5)); params.setToId(null); findCallback = new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { auditDAO.findAuditEntries(callback, params, 2); return null; } }; txnHelper.doInTransaction(findCallback); assertTrue(allTimestamps.subList(2, 4).equals(timestamps)); }