List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:com.migo.controller.SysUserController.java
/** * // w ww.j a v a 2 s.c o m */ @SysLog("") @RequestMapping("/delete") @RequiresPermissions("sys:user:delete") public R delete(@RequestBody Long[] userIds) { if (ArrayUtils.contains(userIds, 1L)) { return R.error("??"); } if (ArrayUtils.contains(userIds, getUserId())) { return R.error("??"); } sysUserService.deleteBatch(userIds); return R.ok(); }
From source file:com.sapienter.jbilling.server.metafields.MetaFieldHelper.java
/** * Sets the value of an ait meta field that is already associated with this object for a given date. If * the field does not already exist, or if the value class is of an incorrect type * then an IllegalArgumentException will be thrown. * * @param customizedEntity entity for search/set fields * @param name field name// ww w . j a v a2 s.com * @param value field value * @throws IllegalArgumentException thrown if field name does not exist, or if value is of an incorrect type. */ public static void setMetaField(Integer entityId, Integer groupId, MetaContent customizedEntity, String name, Object value) throws IllegalArgumentException { MetaFieldValue fieldValue = customizedEntity.getMetaField(name, groupId); if (fieldValue != null) { // common case during editing try { fieldValue.setValue(value); } catch (Exception ex) { throw new IllegalArgumentException("Incorrect type for meta field with name " + name, ex); } } else { EntityType[] types = customizedEntity.getCustomizedEntityType(); if (types == null) { throw new IllegalArgumentException("Meta Fields could not be specified for current entity"); } MetaField fieldName = null; if (null != groupId) { fieldName = new MetaFieldDAS().getFieldByNameTypeAndGroup(entityId, types, name, groupId); } else if (ArrayUtils.contains(types, EntityType.PAYMENT_METHOD_TYPE)) { //TODO MODULARIZATION: UNDERSTAND HERE IF WE CAN AVOID USE THE PaymentInformationDTO fieldName = customizedEntity.fieldNameRetrievalFunction(customizedEntity, name); } else { fieldName = new MetaFieldDAS().getFieldByName(entityId, types, name); } if (fieldName == null) { throw new IllegalArgumentException( "Meta Field with name " + name + " was not defined for current entity"); } MetaFieldValue field = fieldName.createValue(); try { field.setValue(value); } catch (Exception ex) { throw new IllegalArgumentException("Incorrect type for meta field with name " + name, ex); } customizedEntity.setMetaField(field, groupId); } }
From source file:gov.nih.nci.cabig.caaers.service.ScheduledNotificationProcessService.java
/** * This method will process and sends notifications associated to a * scheduled notification. /* w w w. ja va 2s. c om*/ * * - Will find the recipients, and their email addresses. * - Will generate the subject/body of email * - Will send notification * - Will update notification status. * * @param reportId - A valid {@link Report#id} * @param scheduledNotificationId - A valid {@link ScheduledNotification#id} */ @Transactional public void process(Integer reportId, Integer scheduledNotificationId) { Report report = reportDao.getById(reportId); ScheduledEmailNotification scheduledNotification = (ScheduledEmailNotification) report .fetchScheduledNotification(scheduledNotificationId); DeliveryStatus newDeliveryStatus = DeliveryStatus.RECALLED; if (report.isActive()) { newDeliveryStatus = DeliveryStatus.DELIVERED; PlannedEmailNotification plannedNotification = (PlannedEmailNotification) scheduledNotification .getPlanedNotificaiton(); ExpeditedAdverseEventReport aeReport = report.getAeReport(); StudySite studySite = aeReport.getStudySite(); Study study = aeReport.getStudy(); Set<String> emailAddresses = new HashSet<String>(); //find emails of direct recipients List<ContactMechanismBasedRecipient> contactRecipients = plannedNotification .getContactMechanismBasedRecipients(); if (CollectionUtils.isNotEmpty(contactRecipients)) { for (ContactMechanismBasedRecipient recipient : contactRecipients) { String contact = recipient.getContact(); if (GenericValidator.isEmail(contact)) emailAddresses.add(contact); } } //find emails of role recipients List<RoleBasedRecipient> roleRecipients = plannedNotification.getRoleBasedRecipients(); if (CollectionUtils.isNotEmpty(roleRecipients)) { List<String> emails = null; for (RoleBasedRecipient recipient : roleRecipients) { if (ArrayUtils.contains(RoleUtils.reportSpecificRoles, recipient.getRoleName())) { emails = report.findEmailAddressByRole(recipient.getRoleName()); } else if (ArrayUtils.contains(RoleUtils.sponsorAndCoordinatingCenterSpecificRoles, recipient.getRoleName())) { emails = study.getStudyCoordinatingCenter().findEmailAddressByRole(recipient.getRoleName()); emails.addAll(study.getStudyFundingSponsors().get(0) .findEmailAddressByRole(recipient.getRoleName())); } else if (ArrayUtils.contains(RoleUtils.studySiteSpecificRoles, recipient.getRoleName())) { emails = studySite.findEmailAddressByRole(recipient.getRoleName()); } else { emails = study.findEmailAddressByRole(recipient.getRoleName()); } //now add the valid email addresses obtained if (CollectionUtils.isNotEmpty(emails)) { for (String email : emails) { if (GenericValidator.isEmail(email)) emailAddresses.add(email); } } } } if (CollectionUtils.isNotEmpty(emailAddresses)) { //now process the notifications. String rawSubjectLine = plannedNotification.getSubjectLine(); String rawBody = plannedNotification.getNotificationBodyContent().getBody(); Map<Object, Object> contextVariableMap = report.getContextVariables(); //change the reportURL String reportURL = String.valueOf(contextVariableMap.get("reportURL")); contextVariableMap.put("reportURL", configuration.get(Configuration.CAAERS_BASE_URL) + reportURL); //apply the replacements. String subjectLine = freeMarkerService.applyRuntimeReplacementsForReport(rawSubjectLine, contextVariableMap); String body = freeMarkerService.applyRuntimeReplacementsForReport(rawBody, contextVariableMap); //create the message SimpleMailMessage mailMsg = new SimpleMailMessage(); mailMsg.setSentDate(scheduledNotification.getScheduledOn()); mailMsg.setSubject(subjectLine); mailMsg.setText(body); //send email to each recipient for (String email : emailAddresses) { mailMsg.setTo(email); try { caaersJavaMailSender.send(mailMsg); } catch (Exception e) { //no need to throw and rollback logger.warn("Error while emailing to [" + email + "]", e); } } } } scheduledNotificationDao.updateDeliveryStatus(scheduledNotification, scheduledNotification.getDeliveryStatus(), newDeliveryStatus); }
From source file:net.sf.zekr.ui.ZekrGlobalKeyListener.java
public void handleEvent(Event event) { if (quranForm == null || quranForm.shell == null || quranForm.isDisposed()) { return;// w w w.j av a2s .c o m } // boolean mac = GlobalConfig.isMac; // if ((!mac && event.stateMask == SWT.CTRL) || (mac && event.stateMask == SWT.COMMAND)) { // if (event.keyCode == 'f') { // find // this.quranForm.focusOnSearchBox(); // } else if (event.keyCode == 'd') { // bookmark // this.quranForm.quranFormController.bookmarkThis(); // } else if (event.keyCode == 'q') { // quit // this.quranForm.quit(); // } // } else if (event.stateMask == SWT.ALT) { // } else if ((event.keyCode & SWT.KEYCODE_BIT) != 0) { // if (event.keyCode == SWT.F1) { // } else if (event.keyCode == SWT.F4) { // boolean state = !this.quranForm.playerUiController.isAudioControllerFormOpen(); // this.quranForm.qmf.toggleAudioPanelState(state); // this.quranForm.playerUiController.toggleAudioControllerForm(state); // } // } int keyCode = extractSwtBitKeyCode(event); KeyboardShortcut shortcut = config.getShortcut(); if (shortcut != null) { List<KeyboardAction> actionList = shortcut.getKeyActionList(keyCode); if (actionList != null) { String formId = FormUtils.getCurrentFormId(); for (KeyboardAction keyboardAction : actionList) { // check modality Shell activeShell = quranForm.getDisplay().getActiveShell(); if (activeShell != null) { if (keyboardAction.suppressOnModal && isModal(activeShell.getStyle())) { continue; } } if (StringUtils.isNotBlank(keyboardAction.window)) { String[] winList = keyboardAction.window.split(","); if (ArrayUtils.contains(winList, formId) || keyboardAction.global) { quranForm.quranFormController.executeAction(keyboardAction.action); break; } } else if (keyboardAction.global) { quranForm.quranFormController.executeAction(keyboardAction.action); break; } else if (StringUtils.equals(formId, ZekrForm.FORM_ID)) { // act only when QuranForm is active quranForm.quranFormController.executeAction(keyboardAction.action); break; } } } } }
From source file:edu.cornell.med.icb.clustering.TestQTClusterer.java
@Test public void fourInstanceClusteringInOneCluster() { // put one instance in each cluster, total two instances final Clusterer clusterer = new QTClusterer(4); final SimilarityDistanceCalculator distanceCalculator = new MaxLinkageDistanceCalculator() { public double distance(final int i, final int j) { // instances 0 and 1 belong to same cluster if (i == 0 && j == 1 || i == 1 && j == 0) { return 0; } else { return 10; }/*from w ww .j av a 2 s. co m*/ } }; // instances 0,1,2,3 go to cluster 1 (distance(0,1)=0; distance(2,0)=10<=threshold) assertEquals(0d, distanceCalculator.distance(0, 1), DELTA); assertEquals(0d, distanceCalculator.distance(1, 0), DELTA); assertEquals(10d, distanceCalculator.distance(0, 0), DELTA); assertEquals(10d, distanceCalculator.distance(1, 1), DELTA); assertEquals(10d, distanceCalculator.distance(0, 2), DELTA); assertEquals(10d, distanceCalculator.distance(2, 0), DELTA); assertEquals(10d, distanceCalculator.distance(2, 3), DELTA); final List<int[]> clusters = clusterer.cluster(distanceCalculator, 11); assertNotNull(clusters); assertEquals("Expected one cluster", 1, clusters.size()); final int[] cluster = clusters.get(0); assertEquals("First cluster must have size 4", 4, cluster.length); assertTrue("Instance 0 in cluster 0", ArrayUtils.contains(cluster, 0)); assertTrue("Instance 1 in cluster 0", ArrayUtils.contains(cluster, 1)); assertTrue("Instance 2 in cluster 0", ArrayUtils.contains(cluster, 2)); assertTrue("Instance 3 in cluster 0", ArrayUtils.contains(cluster, 3)); }
From source file:com.manydesigns.elements.xml.XmlBuffer.java
public void closeElement(String name) { if (tagStack != null) { String topOfStack;//from w ww. ja v a2s .c om try { topOfStack = tagStack.pop(); } catch (EmptyStackException e) { throw new IllegalStateException("Stack underflow: " + writer.toString(), e); } if (!topOfStack.equals(name)) { throw new IllegalStateException(MessageFormat.format("Expected: {0} - Actual: {1}\n{2}", topOfStack, name, writer.toString())); } } try { switch (state) { case OPEN: if (ArrayUtils.contains(allowedEmptyTags, name)) { writer.write(" />"); } else { writer.write(">"); writer.write("</"); writer.write(name); writer.write(">"); } break; case CLOSE: case TEXT: writer.write("</"); writer.write(name); writer.write(">"); break; default: throw new IllegalStateException("XmlBuffer state " + state); } state = CLOSE; } catch (IOException e) { throw new IOError(e); } }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateParser.java
private void validateSignatureAlgorithm() { result.rejectIfFalse(ArrayUtils.contains(ALLOWED_SIGNATURE_ALGORITHM_OIDS, certificate.getSigAlgOID()), CERTIFICATE_SIGNATURE_ALGORITHM, certificate.getSigAlgOID()); }
From source file:hudson.plugins.clearcase.ucm.service.StreamService.java
public boolean isViewAttachedTo(String viewTag, Stream stream) throws IOException, InterruptedException { return ArrayUtils.contains(getViews(stream), viewTag); }
From source file:de.alpharogroup.random.RandomExtensionsTest.java
/** * Test method for {@link RandomExtensions#getRandomEnum(Enum[])} . *///from w w w.j a v a2 s . co m @Test public void testGetRandomEnumArray() { final Gender[] genders = Gender.values(); final Gender randomEnumEntry = RandomExtensions.getRandomEnum(genders); AssertJUnit.assertTrue("Enum value should contain the random value.", ArrayUtils.contains(genders, randomEnumEntry)); }
From source file:gov.nih.nci.caarray.security.SecurityPolicy.java
/** * Returns whether the given property on the given entity object is allowed by this policy. * @param entity the object in question/*from w ww . jav a 2 s . c o m*/ * @param propertyName the name of the property on the object * @return whether this policy allows the specified property on the specified object to be seen */ private boolean allowProperty(PropertyAccessor propAccessor) { // NOPMD for some reason PMD thinks it's not used AttributePolicy attributePolicy = getAttributePolicy(propAccessor); String[] policyNames = ArrayUtils.EMPTY_STRING_ARRAY; if (attributePolicy != null) { policyNames = (mode == SecurityPolicyMode.WHITELIST) ? attributePolicy.allow() : attributePolicy.deny(); } boolean containsPolicy = ArrayUtils.contains(policyNames, name); return (mode == SecurityPolicyMode.WHITELIST) ? containsPolicy : !containsPolicy; }