List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull
public static boolean isBlankOrNull(String value)
Checks if the field isn't null and length of the field is greater than zero not including whitespace.
From source file:org.ncbo.stanford.service.xml.impl.XMLSerializationServiceImpl.java
private void initResponseBean(Request request, AbstractResponseBean responseBean) { String accessedResource = request.getResourceRef().getPath(); if (!GenericValidator.isBlankOrNull(accessedResource)) { responseBean.setAccessedResource(accessedResource); }/*w ww .j ava2 s. c o m*/ responseBean.setMediaType(getPreferredMediaType(request)); }
From source file:org.openmobster.core.common.validation.CoreValidator.java
/** * Checks if the field is required.//from ww w . jav a2 s . c o m * * @return boolean If the field isn't <code>null</code> and * has a length greater than zero, <code>true</code> is returned. * Otherwise <code>false</code>. */ public static boolean validateRequired(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return !GenericValidator.isBlankOrNull(value); }
From source file:org.openmrs.contrib.metadatarepository.webapp.util.ValidationUtil.java
/** * Validates that two fields match./*from w w w . j av a 2 s. com*/ * @param bean * @param va * @param field * @param errors */ public static boolean validateTwoFields(Object bean, ValidatorAction va, Field field, Errors errors) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { FieldChecks.rejectValue(errors, field, va); return false; } } catch (Exception e) { FieldChecks.rejectValue(errors, field, va); return false; } } return true; }
From source file:org.opentaps.common.party.PartyServices.java
@SuppressWarnings("unchecked") public static Map<String, Object> sendInternalMessage(DispatchContext dctx, Map<String, Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = UtilCommon.getLocale(context); // Get the sender and verify he is able to send im String partyIdFrom = (String) context.get("partyIdFrom"); if (UtilValidate.isEmpty(partyIdFrom)) { partyIdFrom = userLogin.getString("partyId"); }/*from w w w . j ava 2s. co m*/ if (!PartyHelper.isInternalMessageSender(partyIdFrom, delegator)) { return UtilMessage.createServiceError("OpentapsError_InternalMessageNoSenderPermission", locale, context); } // Get the recipients List<String> partyIdTo = (List<String>) context.get("partyIdTo"); if (partyIdTo == null) { partyIdTo = FastList.newInstance(); } String partyIdToAsString = (String) context.get("partyIdToAsString"); String[] toAddrs = partyIdToAsString.split("[,;]"); if (toAddrs.length > 0) { for (String addr : toAddrs) { if (GenericValidator.isBlankOrNull(addr)) { continue; } String addresseeId = (addr.indexOf("<") != -1 && addr.indexOf(">") != -1) ? addr.substring(addr.indexOf("<") + 1, addr.indexOf(">")) : addr; partyIdTo.add(addresseeId.trim()); } } // Get subject of the message String subject = (String) context.get("subject"); // Get the message body String message = (String) context.get("message"); if (UtilValidate.isEmpty(message)) { return UtilMessage.createServiceError("OpentapsError_InternalMessageBodyRequired", locale); } // Send im to every body Iterator<String> parties = partyIdTo.iterator(); while (parties.hasNext()) { // verify the recipient is able to receive internal messages String party = parties.next(); if (!PartyHelper.isInternalMessageRecipient(party, delegator)) { Debug.logError(UtilMessage.expandLabel("OpentapsError_InternalMessageNoRecipientPermission", locale, UtilMisc.toMap("partyId", party)), MODULE); continue; } Map<String, Object> input = UtilMisc.<String, Object>toMap("userLogin", userLogin); input.put("communicationEventTypeId", "INTERNAL_MESSAGE"); input.put("statusId", "COM_ENTERED"); input.put("partyIdFrom", partyIdFrom); input.put("partyIdTo", party); input.put("entryDate", UtilDateTime.nowTimestamp()); input.put("content", message); if (UtilValidate.isNotEmpty(subject)) { input.put("subject", subject); } try { dispatcher.runAsync("createCommunicationEvent", input); } catch (GenericServiceException ex) { return UtilMessage.createAndLogServiceFailure("OpentapsError_InternalMessageNoRecipientPermission", UtilMisc.toMap("partyId", party), locale, MODULE); } } return ServiceUtil.returnSuccess(); }
From source file:org.opentaps.core.service.rpc.XMLRPCServiceImpl.java
/** * Performs actual request selecting configuration and sync/async patter according to * arguments./*from ww w. ja v a 2 s . c o m*/ * * @param config The request configuration. Use default if it is <code>null</code>. * @param methodName The method being performed. * @param params The parameters. * @param callback The callback being notified when the request is finished. Perform sync request if it is <code>null</code>. * @return The result object or <code>null</code> in case async request. * @throws XmlRpcException */ private Object execute(XmlRpcClientConfig config, String methodName, List<?> params, AsyncCallback callback) throws XmlRpcException { if (GenericValidator.isBlankOrNull(methodName)) { throw new IllegalArgumentException("Missing required argument \"methodName\"."); } if (GenericValidator.isBlankOrNull(methodName)) { throw new IllegalArgumentException("Missing parameters to call remote method \"methodName\"."); } if (config == null && this.config == null) { throw new IllegalArgumentException("Not present any configuration in argument or default config."); } if (client == null) { client = new XmlRpcClient(); if (this.config != null) { client.setConfig(this.config); } } XmlRpcClientConfig oldConfig = null; if (config != null) { oldConfig = getConfig(); client.setConfig(config); } ; Object result = null; if (callback == null) { result = client.execute(methodName, params); } else { client.executeAsync(methodName, params, callback); } if (oldConfig != null) { client.setConfig(oldConfig); } return result; }
From source file:org.opentaps.dataimport.CustomerDecoder.java
/** * Create the sales agreement and terms between the given partyId (with a partyName) and the organization. * Entry point which should be called from decode() method. To customize the way agreements are generated * due to field and data differences, overload canCreateSalesAgreement() and createSalesAgreementTerms(). *///from w ww . j a v a 2s. co m public List<GenericValue> createSalesAgreement(GenericValue entry, String partyId, String partyName, Timestamp importTimestamp, Delegator delegator) throws GenericEntityException { List<GenericValue> toBeStored = new FastList<GenericValue>(); if (!canCreateSalesAgreement(entry)) return toBeStored; String agreementId = delegator.getNextSeqId("Agreement"); GenericValue agreement = delegator.makeValue("Agreement"); agreement.put("agreementId", agreementId); agreement.put("partyIdFrom", organizationPartyId); agreement.put("partyIdTo", partyId); agreement.put("agreementTypeId", "SALES_AGREEMENT"); agreement.put("agreementDate", importTimestamp); agreement.put("fromDate", importTimestamp); agreement.put("statusId", "AGR_ACTIVE"); agreement.put("description", "Sales agreement" + (GenericValidator.isBlankOrNull(partyName) ? "" : " for ") + partyName); toBeStored.add(agreement); toBeStored.addAll(createSalesAgreementTerms(entry, agreementId, delegator)); return toBeStored; }
From source file:org.opentaps.notes.domain.impl.NoteJPA.java
/** {@inheritDoc} */ public User getCreatedByUser() { return !GenericValidator.isBlankOrNull(createdByUserId) ? new NoteUser(createdByUserId, userIdType) : null; }
From source file:org.opentaps.notes.repository.impl.NoteRepositoryImpl.java
private Note dbObjectToNote(DBObject noteDoc) { if (noteDoc == null) { return null; }/* ww w . j a v a 2 s. c o m*/ Note note = factory.newInstance(); note.setNoteId(noteDoc.get(NoteMongo.MONGO_ID_FIELD).toString()); note.setNoteText((String) noteDoc.get(Note.Fields.noteText.getName())); if (noteDoc.containsField("createdByUserId")) { String userId = (String) noteDoc.get("createdByUserId"); if (!GenericValidator.isBlankOrNull(userId)) { note.setCreatedByUser(new NoteUser(userId, (String) noteDoc.get("userIdType"))); } } else if (noteDoc.containsField(Note.Fields.createdByUser.getName())) { BasicDBObject userDoc = (BasicDBObject) noteDoc.get(Note.Fields.createdByUser.getName()); if (userDoc != null) { User user = new NoteUser(); Set<Entry<String, Object>> entries = userDoc.entrySet(); for (Entry<String, Object> entry : entries) { user.getProperties().put(entry.getKey(), entry.getValue()); } note.setCreatedByUser(user); } } note.setClientDomain((String) noteDoc.get(Note.Fields.clientDomain.getName())); note.setSequenceNum((Long) noteDoc.get(Note.Fields.sequenceNum.getName())); Date dateTimeCreated = (Date) noteDoc.get(Note.Fields.dateTimeCreated.getName()); if (dateTimeCreated != null) { note.setDateTimeCreated(new Timestamp(dateTimeCreated.getTime())); } // look for custom fields for (String field : noteDoc.keySet()) { if (!note.isBaseField(field)) { note.setAttribute(field, (String) noteDoc.get(field)); } } return note; }
From source file:org.opentaps.notes.rest.FacebookResource.java
/** * Catch callback from facebook//from w ww . j a v a 2 s.c o m * @return Representation */ private Representation callback(String clientCallback, String callbackURL) { Representation rep = new StringRepresentation("Can't get token "); String code = getRequest().getResourceRef().getQueryAsForm().getFirstValue("code"); if (!GenericValidator.isBlankOrNull(code)) { Form form = getAccessToken(code, callbackURL); if (form != null) { String accessToken = form.getFirstValue("access_token"); if (!GenericValidator.isBlankOrNull(accessToken)) { rep = getMe(accessToken); if (rep != null) { String userKey = UUID.randomUUID().toString(); try { JSONObject userJSON = (JSONObject) JSONSerializer.toJSON(rep.getText()); FacebookUser fbUser = new FacebookUser(userJSON); if (fbUser != null) { fbUser.setAccessToken(accessToken); userCache.putUser(userKey, fbUser); Reference ref = new Reference(clientCallback + "?" + USER_KEY_NAME + "=" + userKey); getResponse().redirectTemporary(ref); } } catch (IOException e) { rep = new StringRepresentation("Can't get facebook user from json "); Log.logError(e.toString()); } } else { rep = new StringRepresentation("Can't get facebook user "); } } } } return rep; }
From source file:org.opentaps.notes.rest.locale.Messages.java
public String getMsg(String key, Object... arguments) { try {/*from w w w .ja v a 2s . c o m*/ Locale locale = resourceBundle.getLocale(); if (locale == null || GenericValidator.isBlankOrNull(locale.toString())) { locale = Locale.getDefault(); } return String.format(locale, resourceBundle.getString(key), arguments); } catch (MissingResourceException e) { return key; } }