List of usage examples for java.lang Integer longValue
public long longValue()
From source file:org.egov.dao.budget.BudgetDetailsHibernateDAO.java
private String prepareQuery(final Integer departmentid, final Long functionid, final Integer functionaryid, final Integer schemeid, final Integer subschemeid, final Integer boundaryid, final Integer fundid) { String query = EMPTY_STRING;//from ww w . ja v a 2 s . c om final List<AppConfigValues> list = appConfigValuesService.getConfigValuesByModuleAndKey(EGF, BUDGETARY_CHECK_GROUPBY_VALUES); if (list.isEmpty()) throw new ValidationException(EMPTY_STRING, "budgetaryCheck_groupby_values is not defined in AppConfig"); else { final AppConfigValues appConfigValues = list.get(0); final String[] values = StringUtils.split(appConfigValues.getValue(), ","); for (final String value : values) if (value.equals("department")) { if (departmentid == null || departmentid == 0) throw new ValidationException(EMPTY_STRING, "Department is required"); else query = query + getQuery(Department.class, departmentid.longValue(), " and bd.executingDepartment="); } else if (value.equals("function")) { if (functionid == null || functionid == 0) throw new ValidationException(EMPTY_STRING, "Function is required"); else query = query + getQuery(CFunction.class, functionid, " and bd.function="); } else if ("functionary".equals(value)) { if (functionaryid == null || functionaryid == 0) throw new ValidationException(EMPTY_STRING, "Functionary is required"); else query = query + getQuery(Functionary.class, functionaryid, " and bd.functionary="); } else if (value.equals("fund")) { if (fundid == null || fundid == 0) throw new ValidationException(EMPTY_STRING, "Fund is required"); else query = query + getQuery(Fund.class, fundid, " and bd.fund="); } else if (value.equals("scheme")) { if (schemeid == null || schemeid == 0) throw new ValidationException(EMPTY_STRING, "Scheme is required"); else query = query + getQuery(Scheme.class, schemeid, " and bd.scheme="); } else if (value.equals("subscheme")) { if (subschemeid == null || subschemeid == 0) throw new ValidationException(EMPTY_STRING, "Subscheme is required"); else query = query + getQuery(SubScheme.class, subschemeid, " and bd.subScheme="); } else if (value.equals("boundary")) { if (boundaryid == null || boundaryid == 0) throw new ValidationException(EMPTY_STRING, "Boundary is required"); else query = query + getQuery(Boundary.class, boundaryid.longValue(), " and bd.boundary="); } else throw new ValidationException(EMPTY_STRING, "budgetaryCheck_groupby_values is not matching=" + value); } return " and bd.budget.status.description='Approved' and bd.status.description='Approved' " + query; }
From source file:org.wrml.runtime.schema.generator.SchemaGenerator.java
private String getDefaultValueString(final Value slotValue) { final Context context = getContext(); final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); String defaultValueString = null; if (slotValue instanceof TextValue) { defaultValueString = ((TextValue) slotValue).getDefault(); } else if (slotValue instanceof IntegerValue) { final Integer defaultValue = ((IntegerValue) slotValue).getDefault(); if (defaultValue != null) { defaultValueString = String.valueOf(defaultValue.intValue()); }//from www .java2s. co m } else if (slotValue instanceof SingleSelectValue) { defaultValueString = ((SingleSelectValue) slotValue).getDefault(); } else if (slotValue instanceof MultiSelectValue) { final List<String> defaultValue = ((MultiSelectValue) slotValue).getDefault(); // TODO: Revisit this format defaultValueString = String.valueOf(defaultValue); } else if (slotValue instanceof DateValue) { final Date defaultValue = ((DateValue) slotValue).getDefault(); if (defaultValue != null) { final SyntaxHandler<Date> syntaxHandler = syntaxLoader.getSyntaxHandler(Date.class); defaultValueString = syntaxHandler.formatSyntaxValue(defaultValue); } } else if (slotValue instanceof BooleanValue) { final Boolean defaultValue = ((BooleanValue) slotValue).getDefault(); if (defaultValue != null) { defaultValueString = String.valueOf(defaultValue.booleanValue()); } } else if (slotValue instanceof DoubleValue) { final Double defaultValue = ((DoubleValue) slotValue).getDefault(); if (defaultValue != null) { defaultValueString = String.valueOf(defaultValue.doubleValue()); } } else if (slotValue instanceof LongValue) { final Long defaultValue = ((LongValue) slotValue).getDefault(); if (defaultValue != null) { defaultValueString = String.valueOf(defaultValue.longValue()); } } return defaultValueString; }
From source file:org.jlibrary.core.jcr.JCRRepositoryService.java
public Document updateDocument(Ticket ticket, DocumentProperties properties, InputStream contentStream) throws RepositoryException, SecurityException, ResourceLockedException { // TODO: Check name updates with new code ByteArrayInputStream bais = null; try {/*from w w w .java2s .co m*/ String docId = (String) properties.getProperty(DocumentProperties.DOCUMENT_ID).getValue(); String parentId = (String) properties.getProperty(DocumentProperties.DOCUMENT_PARENT).getValue(); String name = ((String) properties.getProperty(DocumentProperties.DOCUMENT_NAME).getValue()); String description = ((String) properties.getProperty(DocumentProperties.DOCUMENT_DESCRIPTION) .getValue()); Integer typecode = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_TYPECODE).getValue()); Integer position = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_POSITION).getValue()); Integer importance = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_IMPORTANCE) .getValue()); String title = (String) properties.getProperty(DocumentProperties.DOCUMENT_TITLE).getValue(); String url = ((String) properties.getProperty(DocumentProperties.DOCUMENT_URL).getValue()); String language = ((String) properties.getProperty(DocumentProperties.DOCUMENT_LANGUAGE).getValue()); Author author = ((Author) properties.getProperty(DocumentProperties.DOCUMENT_AUTHOR).getValue()); Date metadataDate = ((Date) properties.getProperty(DocumentProperties.DOCUMENT_CREATION_DATE) .getValue()); Calendar date = Calendar.getInstance(); date.setTime(metadataDate); String keywords = ((String) properties.getProperty(DocumentProperties.DOCUMENT_KEYWORDS).getValue()); SessionManager manager = SessionManager.getInstance(); Session session = manager.getSession(ticket); javax.jcr.Node node = session.getNodeByUUID(docId); if (!JCRSecurityService.canWrite(node, ticket.getUser().getId())) { throw new SecurityException(SecurityException.NOT_ENOUGH_PERMISSIONS); } Object syncLock = LockUtility.obtainLock(node); synchronized (syncLock) { locksModule.checkLockAccess(ticket, node); JCRUtils.checkinIfNecessary(node); node.checkout(); node.setProperty(JLibraryConstants.JLIBRARY_DESCRIPTION, description); node.setProperty(JLibraryConstants.JLIBRARY_CREATED, Calendar.getInstance()); node.setProperty(JLibraryConstants.JLIBRARY_IMPORTANCE, importance.longValue()); node.setProperty(JLibraryConstants.JLIBRARY_CREATOR, ticket.getUser().getId()); node.setProperty(JLibraryConstants.JLIBRARY_TYPECODE, typecode.longValue()); node.setProperty(JLibraryConstants.JLIBRARY_POSITION, position.longValue()); node.setProperty(JLibraryConstants.JLIBRARY_TITLE, title); node.setProperty(JLibraryConstants.JLIBRARY_DOCUMENT_URL, url); node.setProperty(JLibraryConstants.JLIBRARY_KEYWORDS, keywords); node.setProperty(JLibraryConstants.JLIBRARY_LANGUAGE, language); node.setProperty(JLibraryConstants.JLIBRARY_CREATION_DATE, date); //Handle relations PropertyDef[] relations = properties.getPropertyList(DocumentProperties.DOCUMENT_DELETE_RELATION); if (relations != null) { for (int i = 0; i < relations.length; i++) { Relation relation = (Relation) relations[i].getValue(); String destinationId = relation.getDestinationNode().getId(); JCRUtils.removeNodeFromProperty(destinationId, node, JLibraryConstants.JLIBRARY_RELATIONS); if (relation.isBidirectional()) { javax.jcr.Node referencedNode = session.getNodeByUUID(destinationId); JCRUtils.removeNodeFromProperty(node.getUUID(), referencedNode, JLibraryConstants.JLIBRARY_RELATIONS); } } } relations = properties.getPropertyList(DocumentProperties.DOCUMENT_ADD_RELATION); if (relations != null) { for (int i = 0; i < relations.length; i++) { Relation relation = (Relation) relations[i].getValue(); String destinationId = relation.getDestinationNode().getId(); JCRUtils.addNodeToProperty(destinationId, node, JLibraryConstants.JLIBRARY_RELATIONS); if (relation.isBidirectional()) { javax.jcr.Node referencedNode = session.getNodeByUUID(destinationId); JCRUtils.addNodeToProperty(node.getUUID(), referencedNode, JLibraryConstants.JLIBRARY_RELATIONS); } } } //Handle authors if (author.equals(Author.UNKNOWN)) { node.setProperty(JLibraryConstants.JLIBRARY_AUTHOR, authorsModule.findUnknownAuthor(ticket)); } else { javax.jcr.Node authorNode = session.getNodeByUUID(author.getId()); node.setProperty(JLibraryConstants.JLIBRARY_AUTHOR, authorNode.getUUID()); } // Handle document categories PropertyDef[] categories = properties.getPropertyList(DocumentProperties.DOCUMENT_DELETE_CATEGORY); if (categories != null) { for (int i = 0; i < categories.length; i++) { String category = (String) categories[i].getValue(); javax.jcr.Node categoryNode = categoriesModule.getCategoryNode(session, category); categoriesModule.removeCategory(ticket, categoryNode, node); } if (categoriesModule.numberOfCategories(node) == 0) { categoriesModule.addUnknownCategory(ticket, node); } } categories = properties.getPropertyList(DocumentProperties.DOCUMENT_ADD_CATEGORY); if (categories != null) { if (categoriesModule.containsUnknownCategory(ticket, node)) { categoriesModule.removeUnknownCategory(ticket, node); } for (int i = 0; i < categories.length; i++) { String category = (String) categories[i].getValue(); javax.jcr.Node categoryNode = categoriesModule.getCategoryNode(session, category); categoriesModule.addCategory(ticket, categoryNode, node); } } // Handle document notes PropertyDef[] notes = properties.getPropertyList(DocumentProperties.DOCUMENT_ADD_NOTE); if (notes != null) { javax.jcr.Node userNode = JCRSecurityService.getUserNode(session, ticket.getUser().getId()); for (int i = 0; i < notes.length; i++) { Note note = (Note) notes[i].getValue(); javax.jcr.Node noteNode = node.addNode(JLibraryConstants.JLIBRARY_NOTE, JLibraryConstants.NOTE_MIXIN); noteNode.addMixin(JCRConstants.JCR_REFERENCEABLE); Calendar noteDate = Calendar.getInstance(); noteDate.setTime(new Date()); noteNode.setProperty(JLibraryConstants.JLIBRARY_DATE, noteDate); noteNode.setProperty(JLibraryConstants.JLIBRARY_TEXT, note.getNote()); noteNode.setProperty(JLibraryConstants.JLIBRARY_USER, userNode.getUUID()); } } notes = properties.getPropertyList(DocumentProperties.DOCUMENT_UPDATE_NOTE); if (notes != null) { for (int i = 0; i < notes.length; i++) { Note note = (Note) notes[i].getValue(); javax.jcr.Node noteNode = session.getNodeByUUID(note.getId()); Calendar noteDate = Calendar.getInstance(); noteDate.setTime(new Date()); noteNode.setProperty(JLibraryConstants.JLIBRARY_DATE, noteDate); noteNode.setProperty(JLibraryConstants.JLIBRARY_TEXT, note.getNote()); noteNode.setProperty(JLibraryConstants.JLIBRARY_USER, ticket.getUser().getId()); } } notes = properties.getPropertyList(DocumentProperties.DOCUMENT_DELETE_NOTE); if (notes != null) { for (int i = 0; i < notes.length; i++) { Note note = (Note) notes[i].getValue(); NodeIterator it = node.getNodes(); while (it.hasNext()) { javax.jcr.Node childNode = (javax.jcr.Node) it.next(); if (childNode.isNodeType(JLibraryConstants.NOTE_MIXIN)) { String noteId = childNode.getUUID(); if (noteId.equals(note.getId())) { childNode.remove(); } } } } } // Handle custom properties List customProperties = properties.getCustomProperties(); Iterator it = customProperties.iterator(); while (it.hasNext()) { PropertyDef property = (PropertyDef) it.next(); node.setProperty(property.getKey().toString(), JCRUtils.getValue(property.getValue())); } // Handle content byte[] content = null; if (properties.getProperty(DocumentProperties.DOCUMENT_CONTENT) != null) { content = (byte[]) properties.getProperty(DocumentProperties.DOCUMENT_CONTENT).getValue(); } if (contentStream != null || content != null) { // need to update content too javax.jcr.Node child = node.getNode(JCRConstants.JCR_CONTENT); InputStream streamToSet; if (contentStream == null) { bais = new ByteArrayInputStream(content); streamToSet = bais; } else { streamToSet = contentStream; } String path = node.getProperty(JLibraryConstants.JLIBRARY_PATH).getString(); String mimeType = Types.getMimeTypeForExtension(FileUtils.getExtension(path)); child.setProperty(JCRConstants.JCR_MIME_TYPE, mimeType); child.setProperty(JCRConstants.JCR_ENCODING, JCRConstants.DEFAULT_ENCODING); child.setProperty(JCRConstants.JCR_DATA, streamToSet); Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(new Date().getTime()); child.setProperty(JCRConstants.JCR_LAST_MODIFIED, lastModified); node.setProperty(JLibraryConstants.JLIBRARY_SIZE, child.getProperty(JCRConstants.JCR_DATA).getLength()); } String previousName = node.getProperty(JLibraryConstants.JLIBRARY_NAME).getString(); if (!previousName.equals(name)) { String path = node.getProperty(JLibraryConstants.JLIBRARY_NAME).getString(); String extension = FileUtils.getExtension(path); String escapedName = JCRUtils.buildValidChildNodeName(node.getParent(), extension, name); if ((extension != null) && !escapedName.endsWith(extension)) { escapedName += extension; } name = Text.unescape(escapedName); node.setProperty(JLibraryConstants.JLIBRARY_NAME, name); session.move(node.getPath(), node.getParent().getPath() + "/" + escapedName); } if (ticket.isAutocommit()) { SaveUtils.safeSaveSession(session); } // create first version node.checkin(); // restore to read-write state node.checkout(); } javax.jcr.Node root = JCRUtils.getRootNode(session); return JCRAdapter.createDocument(node, parentId, root.getUUID()); } catch (Throwable e) { logger.error(e.getMessage(), e); throw new RepositoryException(e); } finally { if (bais != null) { try { bais.close(); } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new RepositoryException(ioe); } } } }
From source file:edu.harvard.iq.dataverse.DatasetPage.java
private List<FileMetadata> selectFileMetadatasForDisplay(String searchTerm) { Set<Long> searchResultsIdSet = null; if (searchTerm != null && !searchTerm.equals("")) { List<Integer> searchResultsIdList = datafileService .findFileMetadataIdsByDatasetVersionIdLabelSearchTerm(workingVersion.getId(), searchTerm, "", ""); searchResultsIdSet = new HashSet<>(); for (Integer id : searchResultsIdList) { searchResultsIdSet.add(id.longValue()); }/*from w ww. j a v a 2 s . c o m*/ } List<FileMetadata> retList = new ArrayList<>(); for (FileMetadata fileMetadata : workingVersion.getFileMetadatasSorted()) { if (searchResultsIdSet == null || searchResultsIdSet.contains(fileMetadata.getId())) { retList.add(fileMetadata); } } return retList; }
From source file:org.jlibrary.core.jcr.JCRRepositoryService.java
private javax.jcr.Node internalCreateDocument(javax.jcr.Session session, Ticket ticket, DocumentProperties properties, InputStream contentStream) throws RepositoryException, SecurityException { ByteArrayInputStream bais = null; try {/*from www. j av a2 s . co m*/ String parentId = (String) properties.getProperty(DocumentProperties.DOCUMENT_PARENT).getValue(); String name = ((String) properties.getProperty(DocumentProperties.DOCUMENT_NAME).getValue()); String path = ((String) properties.getProperty(DocumentProperties.DOCUMENT_PATH).getValue()); String extension = FileUtils.getExtension(path); String description = ((String) properties.getProperty(DocumentProperties.DOCUMENT_DESCRIPTION) .getValue()); Integer typecode = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_TYPECODE).getValue()); Integer position = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_POSITION).getValue()); Integer importance = ((Integer) properties.getProperty(DocumentProperties.DOCUMENT_IMPORTANCE) .getValue()); String title = (String) properties.getProperty(DocumentProperties.DOCUMENT_TITLE).getValue(); String url = ((String) properties.getProperty(DocumentProperties.DOCUMENT_URL).getValue()); String language = ((String) properties.getProperty(DocumentProperties.DOCUMENT_LANGUAGE).getValue()); Author author = ((Author) properties.getProperty(DocumentProperties.DOCUMENT_AUTHOR).getValue()); Date metadataDate = ((Date) properties.getProperty(DocumentProperties.DOCUMENT_CREATION_DATE) .getValue()); Calendar date = Calendar.getInstance(); date.setTime(metadataDate); String keywords = ((String) properties.getProperty(DocumentProperties.DOCUMENT_KEYWORDS).getValue()); javax.jcr.Node parent = session.getNodeByUUID(parentId); if (!JCRSecurityService.canWrite(parent, ticket.getUser().getId())) { throw new SecurityException(SecurityException.NOT_ENOUGH_PERMISSIONS); } String escapedName = JCRUtils.buildValidChildNodeName(parent, extension, name); name = Text.unescape(escapedName); if ((extension != null) && !escapedName.endsWith(extension)) { escapedName += extension; } javax.jcr.Node child = parent.addNode(escapedName, JCRConstants.JCR_FILE); child.addMixin(JCRConstants.JCR_REFERENCEABLE); child.addMixin(JCRConstants.JCR_LOCKABLE); child.addMixin(JCRConstants.JCR_VERSIONABLE); child.addMixin(JLibraryConstants.DOCUMENT_MIXIN); child.setProperty(JLibraryConstants.JLIBRARY_NAME, name); child.setProperty(JLibraryConstants.JLIBRARY_DESCRIPTION, description); child.setProperty(JLibraryConstants.JLIBRARY_CREATED, Calendar.getInstance()); child.setProperty(JLibraryConstants.JLIBRARY_IMPORTANCE, importance.longValue()); child.setProperty(JLibraryConstants.JLIBRARY_CREATOR, ticket.getUser().getId()); child.setProperty(JLibraryConstants.JLIBRARY_TYPECODE, typecode.longValue()); child.setProperty(JLibraryConstants.JLIBRARY_POSITION, position.longValue()); child.setProperty(JLibraryConstants.JLIBRARY_TITLE, title); child.setProperty(JLibraryConstants.JLIBRARY_DOCUMENT_URL, url); child.setProperty(JLibraryConstants.JLIBRARY_KEYWORDS, keywords); child.setProperty(JLibraryConstants.JLIBRARY_LANGUAGE, language); child.setProperty(JLibraryConstants.JLIBRARY_CREATION_DATE, date); child.setProperty(JLibraryConstants.JLIBRARY_PATH, getPath(parent) + FileUtils.getFileName(path)); // Handle authors if (author.equals(Author.UNKNOWN)) { child.setProperty(JLibraryConstants.JLIBRARY_AUTHOR, authorsModule.findUnknownAuthor(ticket)); } else { javax.jcr.Node authorNode = session.getNodeByUUID(author.getId()); child.setProperty(JLibraryConstants.JLIBRARY_AUTHOR, authorNode.getUUID()); } // Handle document categories child.setProperty(JLibraryConstants.JLIBRARY_CATEGORIES, new Value[] {}); PropertyDef[] categories = properties.getPropertyList(DocumentProperties.DOCUMENT_ADD_CATEGORY); if (categories != null) { for (int i = 0; i < categories.length; i++) { String category = (String) categories[i].getValue(); javax.jcr.Node categoryNode = categoriesModule.getCategoryNode(session, category); categoriesModule.addCategory(ticket, categoryNode, child); } } else { categoriesModule.addUnknownCategory(ticket, child); } // Handle document relations child.setProperty(JLibraryConstants.JLIBRARY_RELATIONS, new Value[] {}); // Handle document restrictions child.setProperty(JLibraryConstants.JLIBRARY_RESTRICTIONS, new Value[] {}); javax.jcr.Node userNode = JCRSecurityService.getUserNode(session, ticket.getUser().getId()); addRestrictionsToNode(child, parent, userNode); // Handle document resources. child.setProperty(JLibraryConstants.JLIBRARY_RESOURCES, new Value[] {}); javax.jcr.Node resNode = child.addNode(JcrConstants.JCR_CONTENT, JCRConstants.JCR_RESOURCE); resNode.addMixin(JLibraryConstants.CONTENT_MIXIN); InputStream streamToSet; if (contentStream == null) { byte[] content = (byte[]) properties.getProperty(DocumentProperties.DOCUMENT_CONTENT).getValue(); if (content == null) { // Empty file content = new byte[] {}; } bais = new ByteArrayInputStream(content); streamToSet = bais; } else { streamToSet = contentStream; } //TODO: Handle encoding String mimeType = Types.getMimeTypeForExtension(FileUtils.getExtension(path)); resNode.setProperty(JCRConstants.JCR_MIME_TYPE, mimeType); resNode.setProperty(JCRConstants.JCR_ENCODING, JCRConstants.DEFAULT_ENCODING); resNode.setProperty(JCRConstants.JCR_DATA, streamToSet); Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(new Date().getTime()); resNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, lastModified); child.setProperty(JLibraryConstants.JLIBRARY_SIZE, resNode.getProperty(JCRConstants.JCR_DATA).getLength()); return child; } catch (Throwable e) { logger.error(e.getMessage(), e); throw new RepositoryException(e); } finally { if (bais != null) { try { bais.close(); } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); throw new RepositoryException(ioe); } } } }
From source file:org.nuclos.server.ruleengine.RuleInterface.java
/** * * @param reportName/*from w ww . j av a 2 s . co m*/ * @param entity * @param iObjectId * @param objectFieldForReportName (if set report name would be like "reportName_VALUE-OF-THIS-FIELD.pdf" otherwise "reportName.pdf") * @param nameWithTimestamp (is set report name would be like "reportName_2010-06-01 12-05-00.pdf" otherwise "reportName.pdf" * both, objectFieldForReportName and nameWithTimestamp could be combined! * @param paramsArg report parameters (intid will be added automatically) */ public Collection<NuclosFile> runPDFReport(String reportName, String entity, Integer iObjectId, String objectFieldForReportName, boolean nameWithTimestamp, Map<String, Object> paramsArg) { if (reportName == null) { throw new NuclosFatalRuleException("reportName could not be null"); } if (entity == null) { throw new NuclosFatalRuleException("entity could not be null"); } if (iObjectId == null) { throw new NuclosFatalRuleException("iObjectId could not be null"); } final ReportFacadeRemote reportFacade = ServerServiceLocator.getInstance() .getFacade(ReportFacadeRemote.class); final CollectableSearchCondition clctcond = SearchConditionUtils.newEOComparison( NuclosEntity.REPORT.getEntityName(), "name", ComparisonOperator.EQUAL, reportName, MetaDataServerProvider.getInstance()); final List<EntityObjectVO> lstReport = NucletDalProvider.getInstance() .getEntityObjectProcessor(NuclosEntity.REPORT.getEntityName()) .getBySearchExpression(new CollectableSearchExpression(clctcond)); String fileName = reportName; if (objectFieldForReportName != null) { String fieldValue = (String) this.getRuleInterface().getEntityObject(entity, iObjectId.longValue()) .getFields().get(objectFieldForReportName); fileName += fieldValue != null ? ("_" + fieldValue) : ""; } if (nameWithTimestamp) { final DateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault()); fileName += "_" + dateformat.format(Calendar.getInstance(Locale.getDefault()).getTime()); } final Map<String, Object> mpParams = new HashMap<String, Object>(paramsArg); mpParams.put("intid", iObjectId); mpParams.put("iGenericObjectId", iObjectId); final Set<ReportOutputVO> reportOutputs = new HashSet<ReportOutputVO>(); for (EntityObjectVO reportVO : lstReport) { for (ReportOutputVO outputVO : reportFacade.getReportOutputs(reportVO.getId().intValue())) { if (outputVO.getFormat().equals(ReportOutputVO.Format.PDF)) { reportOutputs.add(outputVO); } } } if (reportOutputs.isEmpty()) { throw new NuclosFatalRuleException( StringUtils.getParameterizedExceptionMessage("rule.interface.error.18", reportName)); } final Collection<NuclosFile> result = new ArrayList<NuclosFile>(); int countOutputs = 1; for (final ReportOutputVO outputVO : reportOutputs) { final String name = fileName; final int index = countOutputs; NuclosLocalServerSession.getInstance().runUnrestricted(new Runnable() { @Override public void run() { try { final NuclosFile file = reportFacade.prepareReport(outputVO.getId(), mpParams, null); result.add(new NuclosFile(name + (reportOutputs.size() > 1 ? ("_" + index) : "") + ".pdf", file.getFileContents())); } catch (CommonBusinessException e) { throw new NuclosFatalRuleException(e); } } }); countOutputs++; } return result; }
From source file:de.hybris.platform.configurablebundleservices.bundle.impl.DefaultBundleCommerceCartServiceIntegrationTest.java
@Test public void testUpdateQuantityForCartEntryBundle() throws CommerceCartModificationException { // Add new entry (device product, standalone) List<CommerceCartModification> modifications = bundleCommerceCartService.addToCart(telcoMasterCart, productModelGalaxyNexus, 2, unitModel, false, NO_BUNDLE, null, false, "<no xml>"); assertEquals(1, modifications.size()); assertNotNull(modifications.iterator().next().getEntry()); final Integer entryMasterNoBundle = modifications.iterator().next().getEntry().getEntryNumber(); // Add new entry (device product, new bundle (number=1)) bundleCommerceCartService.addToCart(telcoMasterCart, productModelGalaxyNexus, 1, unitModel, false, NEW_BUNDLE, bundleSmartPhoneDeviceSelection, false, "<no xml>"); // Add new entry (plan product with billing freq = monthly, existing bundle (number=1)) bundleCommerceCartService.addToCart(telcoMasterCart, subscriptionProductModelMonthly, 1, unitModel, true, 1, bundleSmartPhonePlanSelection, false, "<no xml>"); // Add new entry (plan product with billing freq = yearly, existing bundle (number=1)) modifications.clear();/*from www. ja v a 2s. com*/ modifications = bundleCommerceCartService.addToCart(telcoMasterCart, subscriptionProductModelYearly, 1, unitModel, true, 1, bundleSmartPhoneValuePackSelection2, false, "<no xml>"); assertEquals(1, modifications.size()); assertNotNull(modifications.iterator().next().getEntry()); final Integer entryChildYearlyBundle1 = modifications.iterator().next().getEntry().getEntryNumber(); // Add new entry (device product, new bundle (number=2)) bundleCommerceCartService.addToCart(telcoMasterCart, productModelIPhone, 1, unitModel, false, NEW_BUNDLE, bundleIPhoneDeviceSelection, false, "<no xml>"); // Add new entry (plan product with billing freq = paynow, existing bundle (number=2)) bundleCommerceCartService.addToCart(telcoMasterCart, subscriptionProductModelPaynow, 1, unitModel, true, 2, bundleIPhoneAddonSelection, false, "<no xml>"); // Add new entry (plan product with billing freq = quarterly, existing bundle (number=2)) bundleCommerceCartService.addToCart(telcoMasterCart, subscriptionProductModelQuarterly, 1, unitModel, true, 2, bundleIPhonePlanSelection, false, "<no xml>"); // Add new entry (plan product with billing freq = quarterly, standalone) modifications.clear(); modifications = bundleCommerceCartService.addToCart(telcoMasterCart, subscriptionProductModelQuarterly, 1, unitModel, true, NO_BUNDLE, null, false, "<no xml>"); assertEquals(1, modifications.size()); assertEquals(1, telcoMasterCart.getLastModifiedEntries().size()); assertNotNull(modifications.iterator().next().getEntry()); //Multi cart looks like this now : //@formatter:off // // - master cart (pay now): // - 2 PRODUCT_MODEL_CODE (Standalone) // - 1 PRODUCT_MODEL_CODE (bundle 1) // - 1 PRODUCT_MODEL_CODE (bundle 2) // - 1 SUBSCRIPTION_PRODUCT_CODE_PAYNOW (bundle 2) // - child cart (monthly): // - 1 SUBSCRIPTION_PRODUCT_CODE_MONTHLY (bundle 1) // - child cart (yearly): // - 1 SUBSCRIPTION_PRODUCT_CODE_YEARLY (bundle 1) // - child cart (quarterly): // - 1 SUBSCRIPTION_PRODUCT_CODE_QUARTERLY (bundle 2) // - 1 SUBSCRIPTION_PRODUCT_CODE_QUARTERLY (Standalone) // //@formatter:on assertEquals(8, telcoMasterCart.getEntries().size()); assertEquals(3, telcoMasterCart.getChildren().size()); // Update standalone product in master cart CommerceCartModification result = bundleCommerceCartService.updateQuantityForCartEntry(telcoMasterCart, entryMasterNoBundle.longValue(), 4); assertEquals(Long.valueOf(4), result.getEntry().getQuantity()); assertEquals(3, telcoMasterCart.getChildren().size()); assertEquals(8, telcoMasterCart.getEntries().size()); assertEquals(1, telcoMasterCart.getLastModifiedEntries().size()); assertEquals(result.getEntry(), telcoMasterCart.getLastModifiedEntries().iterator().next()); // Update bundle product in child cart (yearly) to 0, child cart should be removed result = bundleCommerceCartService.updateQuantityForCartEntry(telcoMasterCart, entryChildYearlyBundle1.longValue(), 0); assertEquals(-1, result.getQuantityAdded()); assertEquals(CommerceCartModificationStatus.SUCCESS, result.getStatusCode()); assertEquals(2, telcoMasterCart.getChildren().size()); assertNull(getChildCartForBillingTime(telcoMasterCart, subscriptionProductModelYearly.getSubscriptionTerm().getBillingPlan().getBillingFrequency())); assertEquals(7, telcoMasterCart.getEntries().size()); assertTrue(CollectionUtils.isEmpty(telcoMasterCart.getLastModifiedEntries())); // Update standalone product child cart (quarterly) to 0 final List<CartEntryModel> quarterlyEntries = cartService.getEntriesForProduct(telcoMasterCart, subscriptionProductModelQuarterly); assertEquals(2, quarterlyEntries.size()); for (final CartEntryModel quarterlyEntry : quarterlyEntries) { if (quarterlyEntry.getBundleNo().intValue() == 0) { result = bundleCommerceCartService.updateQuantityForCartEntry(telcoMasterCart, quarterlyEntry.getEntryNumber().intValue(), 0); } } assertEquals(-1, result.getQuantityAdded()); assertEquals(CommerceCartModificationStatus.SUCCESS, result.getStatusCode()); assertEquals(2, telcoMasterCart.getChildren().size()); final CartModel cartModel = getChildCartForBillingTime(telcoMasterCart, subscriptionProductModelQuarterly.getSubscriptionTerm().getBillingPlan().getBillingFrequency()); assertNotNull(cartModel); assertEquals(1, cartModel.getEntries().size()); assertEquals(6, telcoMasterCart.getEntries().size()); assertTrue(CollectionUtils.isEmpty(telcoMasterCart.getLastModifiedEntries())); }
From source file:org.finra.herd.service.impl.BusinessObjectDataServiceImpl.java
@NamespacePermission(fields = "#businessObjectDataSearchRequest.businessObjectDataSearchFilters[0].BusinessObjectDataSearchKeys[0].namespace", permissions = NamespacePermissionEnum.READ) @Override/* w w w . ja v a 2 s. c om*/ public BusinessObjectDataSearchResultPagingInfoDto searchBusinessObjectData(Integer pageNum, Integer pageSize, BusinessObjectDataSearchRequest businessObjectDataSearchRequest) { // TODO: Check name space permission for all entries in the request. // Validate the business object data search request. businessObjectDataSearchHelper.validateBusinessObjectDataSearchRequest(businessObjectDataSearchRequest); // Get the maximum number of results that can be returned on any page of data. The "pageSize" query parameter should not be greater than // this value or an HTTP status of 400 (Bad Request) error would be returned. int maxResultsPerPage = configurationHelper .getProperty(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_PAGE_SIZE, Integer.class); // Validate the page number and page size // Set the defaults if pageNum and pageSize are null // Page number must be greater than 0 // Page size must be greater than 0 and less than maximum page size pageNum = businessObjectDataSearchHelper.validatePagingParameter("pageNum", pageNum, 1, Integer.MAX_VALUE); pageSize = businessObjectDataSearchHelper.validatePagingParameter("pageSize", pageSize, maxResultsPerPage, maxResultsPerPage); // Get the maximum record count that is configured in the system. Integer businessObjectDataSearchMaxResultCount = configurationHelper .getProperty(ConfigurationValue.BUSINESS_OBJECT_DATA_SEARCH_MAX_RESULT_COUNT, Integer.class); // Get the business object data search key. // We assume that the input list contains only one filter with a single search key, since validation should be passed by now. BusinessObjectDataSearchKey businessObjectDataSearchKey = businessObjectDataSearchRequest .getBusinessObjectDataSearchFilters().get(0).getBusinessObjectDataSearchKeys().get(0); // Validate partition keys in partition value filters. if (CollectionUtils.isNotEmpty(businessObjectDataSearchKey.getPartitionValueFilters())) { // Get a count of business object formats that match the business object data search key parameters without the list of partition keys. Long businessObjectFormatRecordCount = businessObjectFormatDao .getBusinessObjectFormatCountByPartitionKeys(businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName(), businessObjectDataSearchKey.getBusinessObjectFormatUsage(), businessObjectDataSearchKey.getBusinessObjectFormatFileType(), businessObjectDataSearchKey.getBusinessObjectFormatVersion(), null); // If business object format record count is zero, we return an empty result list. if (businessObjectFormatRecordCount == 0) { return new BusinessObjectDataSearchResultPagingInfoDto(pageNum.longValue(), pageSize.longValue(), 0L, 0L, 0L, (long) maxResultsPerPage, new BusinessObjectDataSearchResult(new ArrayList<>())); } // Get partition keys from the list of partition value filters. List<String> partitionKeys = new ArrayList<>(); for (PartitionValueFilter partitionValueFilter : businessObjectDataSearchKey .getPartitionValueFilters()) { // Get partition key from the partition value filter. Partition key should not be empty, since validation is passed by now. partitionKeys.add(partitionValueFilter.getPartitionKey()); } // Get a count of business object formats that match the business object data search key parameters and the list of partition keys. businessObjectFormatRecordCount = businessObjectFormatDao.getBusinessObjectFormatCountByPartitionKeys( businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName(), businessObjectDataSearchKey.getBusinessObjectFormatUsage(), businessObjectDataSearchKey.getBusinessObjectFormatFileType(), businessObjectDataSearchKey.getBusinessObjectFormatVersion(), partitionKeys); // Fail if business object formats found that contain specified partition keys in their schema. Assert.isTrue(businessObjectFormatRecordCount > 0, String.format( "There are no registered business object formats with \"%s\" namespace, \"%s\" business object definition name", businessObjectDataSearchKey.getNamespace(), businessObjectDataSearchKey.getBusinessObjectDefinitionName()) + (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatUsage()) ? String.format(", \"%s\" business object format usage", businessObjectDataSearchKey.getBusinessObjectFormatUsage()) : "") + (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType()) ? String.format(", \"%s\" business object format file type", businessObjectDataSearchKey.getBusinessObjectFormatFileType()) : "") + (businessObjectDataSearchKey.getBusinessObjectFormatVersion() != null ? String.format(", \"%d\" business object format version", businessObjectDataSearchKey.getBusinessObjectFormatVersion()) : "") + String.format(" that have schema with partition columns matching \"%s\" partition key(s).", String.join(", ", partitionKeys))); } // Get the total record count up to to the maximum allowed record count that is configured in the system plus one more record. Integer totalRecordCount = businessObjectDataDao.getBusinessObjectDataLimitedCountBySearchKey( businessObjectDataSearchKey, businessObjectDataSearchMaxResultCount + 1); // Validate the total record count. if (totalRecordCount > businessObjectDataSearchMaxResultCount) { throw new IllegalArgumentException( String.format("Result limit of %d exceeded. Modify filters to further limit results.", businessObjectDataSearchMaxResultCount)); } // If total record count is zero, we return an empty result list. Otherwise, execute the search. List<BusinessObjectData> businessObjectDataList = totalRecordCount == 0 ? new ArrayList<>() : businessObjectDataDao.searchBusinessObjectData(businessObjectDataSearchKey, pageNum, pageSize); // Get the page count. Integer pageCount = totalRecordCount / pageSize + (totalRecordCount % pageSize > 0 ? 1 : 0); // Build and return the business object data search result with the paging information. return new BusinessObjectDataSearchResultPagingInfoDto(pageNum.longValue(), pageSize.longValue(), pageCount.longValue(), (long) businessObjectDataList.size(), totalRecordCount.longValue(), (long) maxResultsPerPage, new BusinessObjectDataSearchResult(businessObjectDataList)); }
From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java
/** * returns a list of SystemOverview objects that contain the given package id * @param loggedInUser The current user// ww w.j av a2s . co m * @param pid the package id to search for * @return an array of systemOverview objects * * @xmlrpc.doc Lists the systems that have the given installed package * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param_desc("int", "pid", "the package id") * @xmlrpc.returntype * #array() * $SystemOverviewSerializer * #array_end() */ public List<SystemOverview> listSystemsWithPackage(User loggedInUser, Integer pid) { Package pack = PackageFactory.lookupByIdAndOrg(pid.longValue(), loggedInUser.getOrg()); if (pack == null) { throw new InvalidPackageException(pid.toString()); } return SystemManager.listSystemsWithPackage(loggedInUser, pid.longValue()); }
From source file:com.redhat.rhn.frontend.xmlrpc.system.SystemHandler.java
/** * Lists all of the notes that are associated with a system. * If no notes are found it should return an empty set. * @param loggedInUser The current user/* ww w. j a v a 2 s. c o m*/ * @param sid the system id * @return Array of Note objects associated with the given system * * @xmlrpc.doc Provides a list of notes associated with a system. * @xmlrpc.param #param("string", "sessionKey") * @xmlrpc.param #param("int", "serverId") * @xmlrpc.returntype * #array() * $NoteSerializer * #array_end() */ public Set<Note> listNotes(User loggedInUser, Integer sid) { Server server = SystemManager.lookupByIdAndUser(new Long(sid.longValue()), loggedInUser); return server.getNotes(); }