List of usage examples for org.apache.commons.lang StringUtils INDEX_NOT_FOUND
int INDEX_NOT_FOUND
To view the source code for org.apache.commons.lang StringUtils INDEX_NOT_FOUND.
Click Source Link
From source file:com.oneops.opamp.service.Notifications.java
/** * Send ops event notification./*www . j av a2 s . c o m*/ * * @param event change event for which the notification needs to be sent. * @param note Additional note for notification. * @param severity severity of notification * */ public NotificationMessage sendOpsEventNotification(CiChangeStateEvent event, String note, NotificationSeverity severity, String subject, String text, Map<String, Object> payloadEntries) { OpsBaseEvent oEvent = getEventUtil().getOpsEvent(event); if (oEvent == null) return null; CmsCI ci = cmProcessor.getCiById(oEvent.getCiId()); if (ci == null) { logger.error("Can not get CmsCI for id - " + oEvent.getCiId()); return null; } NotificationMessage notify = new NotificationMessage(); notify.setType(NotificationType.ci); notify.setCmsId(oEvent.getCiId()); notify.setSource(NOTIFICATION_SOURCE); notify.setNsPath(ci.getNsPath()); notify.setTimestamp(oEvent.getTimestamp()); notify.setCloudName(event.getCloudName()); notify.putPayloadEntry(EVENT_NAME, oEvent.getSource()); notify.putPayloadEntry(CI_NAME, ci.getCiName()); notify.putPayloadEntry(STATUS, oEvent.getStatus()); notify.putPayloadEntry(OLD_STATE, event.getOldState()); notify.putPayloadEntry(NEW_STATE, event.getNewState()); notify.putPayloadEntry(CLASS_NAME, ci.getCiClassName()); notify.putPayloadEntry(STATE, oEvent.getState()); if (oEvent.getMetrics() != null) { notify.putPayloadEntry(METRICS, gson.toJson(oEvent.getMetrics())); } addIpToNotification(ci, notify); if (payloadEntries != null && payloadEntries.size() > 0) { notify.putPayloadEntries(payloadEntries); } notify.setManifestCiId(oEvent.getManifestId()); if (event.getComponentStatesCounters() != null) { for (String counterName : event.getComponentStatesCounters().keySet()) { notify.putPayloadEntry(counterName, String.valueOf(event.getComponentStatesCounters().get(counterName))); } } // tomcat-compute-cpu:HighCpuUsage->split. // app-tomcat-JvmInfo:PANGAEA:APP:US:Taxo_Svc:jvm:memory int index = StringUtils.ordinalIndexOf(oEvent.getName(), COLON, 1); if (index != StringUtils.INDEX_NOT_FOUND) { String threshHoldName = oEvent.getName().substring(index + 1); notify.putPayloadEntry(THRESHOLD, threshHoldName); } CmsCI envCi = envProcessor.getEnv4Bom(ci.getCiId()); CmsCIAttribute envProfileAttrib = envCi.getAttribute(PROFILE_ATTRIBUTE_NAME); if (envProfileAttrib != null) { notify.setEnvironmentProfileName(envProfileAttrib.getDfValue()); } CmsCIAttribute adminStatusAttrib = envCi.getAttribute(ADMINSTATUS_ATTRIBUTE_NAME); if (adminStatusAttrib != null) { notify.setAdminStatus(envCi.getAttribute(ADMINSTATUS_ATTRIBUTE_NAME).getDfValue()); } notify.setManifestCiId(oEvent.getManifestId()); String subjectPrefix = NotificationMessage.buildSubjectPrefix(ci.getNsPath()); if (oEvent.getState().equalsIgnoreCase("open")) { if (severity == null) { notify.setSeverity(NotificationSeverity.warning); } else { notify.setSeverity(severity); } if (StringUtils.isNotEmpty(subject)) { notify.setSubject(subjectPrefix + subject); } else { notify.setSubject(subjectPrefix + oEvent.getName() + SUBJECT_SUFFIX_OPEN_EVENT); } //subject = <monitorName:[threshold_name|heartbeat]> [is violated|recovered] // text = <ciName> is <newState>, <<opamp action/notes>> if (StringUtils.isNotEmpty(text)) { notify.setText(text); } else { notify.setText(ci.getCiName() + " is in " + event.getNewState() + " state"); } } else if (oEvent.getState().equalsIgnoreCase("close")) { // close events go on INFO notify.setSeverity(NotificationSeverity.info); if (StringUtils.isNotEmpty(subject)) { notify.setSubject(subjectPrefix + subject); } else { notify.setSubject(subjectPrefix + oEvent.getName() + SUBJECT_SUFFIX_CLOSE_EVENT); } if (StringUtils.isNotEmpty(text)) { notify.setText(text); } else { notify.setText(ci.getCiName() + " is in " + event.getNewState() + " state"); } } if (StringUtils.isNotEmpty(note)) { notify.appendText("; " + note); } else { notify.appendText("."); } if (logger.isDebugEnabled()) { Gson gson = new Gson(); logger.debug(gson.toJson(notify)); } antennaClient.executeAsync(notify); return notify; }
From source file:eu.eidas.auth.engine.SamlEngine.java
/** * Gets the country from X.509 Certificate. * * @param keyInfo the key info// w ww . j av a 2 s.c o m * @return the country */ private String getCountry(KeyInfo keyInfo) { LOG.trace("Recover country information."); try { org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0).getX509Certificates() .get(0); // Transform the KeyInfo to X509Certificate. X509Certificate cert = CertificateUtil.toCertificate(xmlCert.getValue()); String distName = cert.getSubjectDN().toString(); distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName)); String countryCode = "C="; int init = distName.indexOf(countryCode); String result = ""; if (init > StringUtils.INDEX_NOT_FOUND) { // Exist country code. int end = distName.indexOf(',', init); if (end <= StringUtils.INDEX_NOT_FOUND) { end = distName.length(); } if (init < end && end > StringUtils.INDEX_NOT_FOUND) { result = distName.substring(init + countryCode.length(), end); //It must be a two characters value if (result.length() > 2) { result = result.substring(0, 2); } } } return result.trim(); } catch (EIDASSAMLEngineException e) { LOG.error(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate: " + e.getMessage(), e); throw new EIDASSAMLEngineRuntimeException(e); } }
From source file:eu.eidas.auth.engine.EIDASSAMLEngine.java
/** * Gets the country from X.509 Certificate. * //from ww w . java 2 s .co m * @param keyInfo the key info * * @return the country */ private String getCountry(final KeyInfo keyInfo) { LOG.trace("Recover country information."); String result = ""; try { final org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0) .getX509Certificates().get(0); // Transform the KeyInfo to X509Certificate. CertificateFactory certFact; certFact = CertificateFactory.getInstance("X.509"); final ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(xmlCert.getValue())); final X509Certificate cert = (X509Certificate) certFact.generateCertificate(bis); String distName = cert.getSubjectDN().toString(); distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName)); final String countryCode = "C="; final int init = distName.indexOf(countryCode); if (init > StringUtils.INDEX_NOT_FOUND) { // Exist country code. int end = distName.indexOf(',', init); if (end <= StringUtils.INDEX_NOT_FOUND) { end = distName.length(); } if (init < end && end > StringUtils.INDEX_NOT_FOUND) { result = distName.substring(init + countryCode.length(), end); //It must be a two characters value if (result.length() > 2) { result = result.substring(0, 2); } } } } catch (CertificateException e) { LOG.info(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate. {}", e.getMessage()); LOG.debug(SAML_EXCHANGE, "BUSINESS EXCEPTION : Procces getCountry from certificate. {}", e); } return result.trim(); }
From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java
/** * Gets the country from X.509 Certificate. * /*from ww w . j a v a 2s . com*/ * @param keyInfo the key info * * @return the country */ private String getCountry(final KeyInfo keyInfo) { LOG.debug("Recover country information."); String result = ""; try { final org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0) .getX509Certificates().get(0); // Transform the KeyInfo to X509Certificate. CertificateFactory certFact; certFact = CertificateFactory.getInstance("X.509"); final ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(xmlCert.getValue())); final X509Certificate cert = (X509Certificate) certFact.generateCertificate(bis); String distName = cert.getSubjectDN().toString(); distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName)); final String countryCode = "C="; final int init = distName.indexOf(countryCode); if (init > StringUtils.INDEX_NOT_FOUND) { // Exist country code. int end = distName.indexOf(',', init); if (end <= StringUtils.INDEX_NOT_FOUND) { end = distName.length(); } if (init < end && end > StringUtils.INDEX_NOT_FOUND) { result = distName.substring(init + countryCode.length(), end); //It must be a two characters value if (result.length() > 2) { result = result.substring(0, 2); } } } } catch (CertificateException e) { LOG.error("Procces getCountry from certificate."); } return result.trim(); }
From source file:org.apache.qpid.server.security.access.config.RuleSet.java
/** Returns true if a username has the name[@domain][/realm] format */ protected boolean isvalidUserName(String name) { // check for '@' and '/' in namne int atPos = name.indexOf(AT); int slashPos = name.indexOf(SLASH); boolean atFound = atPos != StringUtils.INDEX_NOT_FOUND && atPos == name.lastIndexOf(AT); boolean slashFound = slashPos != StringUtils.INDEX_NOT_FOUND && slashPos == name.lastIndexOf(SLASH); // must be at least one character after '@' or '/' if (atFound && atPos > name.length() - 2) { return false; }/*w ww .j av a 2 s . c o m*/ if (slashFound && slashPos > name.length() - 2) { return false; } // must be at least one character between '@' and '/' if (atFound && slashFound) { return (atPos < (slashPos - 1)); } // otherwise all good return true; }
From source file:org.codice.proxy.http.HttpProxyCamelHttpTransportServlet.java
private String getEndpointNameFromPath(String path) { // path is like: "/example1/something/0/thing.html" // or is like: "/example1" // endpointName is: "example1" String endpointName = (StringUtils.indexOf(path, "/", 1) != StringUtils.INDEX_NOT_FOUND) ? StringUtils.substring(path, 0, StringUtils.indexOf(path, "/", 1)) : path;/*from w ww . j a va 2s. c o m*/ endpointName = StringUtils.remove(endpointName, "/"); return endpointName; }
From source file:org.kuali.kfs.module.ar.businessobject.lookup.ContractsGrantsInvoiceDocumentErrorLogLookupableHelperServiceImpl.java
/** * Manipulate fields for search criteria in order to get the results the user really wants. * * @param fieldValues//from ww w. ja v a 2s .com * @return updated search criteria fieldValues */ protected Map<String, String> updateFieldValuesForSearchCriteria(Map<String, String> fieldValues) { Map<String, String> newFieldValues = new HashMap<>(); newFieldValues.putAll(fieldValues); // Add wildcard character to start and end of accounts field so users can search for single account // within the delimited list of accounts without having to add the wildcards explicitly themselves. String accounts = newFieldValues .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS); if (StringUtils.isNotBlank(accounts)) { // only add wildcards if they haven't already been added (for some reason this method gets called twice when generating the pdf report) if (!StringUtils.startsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) { accounts = KFSConstants.WILDCARD_CHARACTER + accounts; } if (!StringUtils.endsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) { accounts += KFSConstants.WILDCARD_CHARACTER; } } newFieldValues.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS, accounts); // Increment to error date by one day so that the correct results are retrieved. // Since the error date is stored as both a date and time in the database records with an error date // the same as the error date the user enters on the search criteria aren't retrieved without this modification. String errorDate = newFieldValues .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ERROR_DATE_TO); int index = StringUtils.indexOf(errorDate, SearchOperator.LESS_THAN_EQUAL.toString()); if (index == StringUtils.INDEX_NOT_FOUND) { index = StringUtils.indexOf(errorDate, SearchOperator.BETWEEN.toString()); if (index != StringUtils.INDEX_NOT_FOUND) { incrementErrorDate(newFieldValues, errorDate, index); } } else { incrementErrorDate(newFieldValues, errorDate, index); } return newFieldValues; }
From source file:org.kuali.rice.krad.service.impl.KRADLegacyDataAdapterImpl.java
@Override public org.kuali.rice.krad.bo.DataObjectRelationship getDataObjectRelationship(Object dataObject, Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly, boolean supportsLookup, boolean supportsInquiry) { RelationshipDefinition ddReference = getDictionaryRelationship(dataObjectClass, attributeName); org.kuali.rice.krad.bo.DataObjectRelationship relationship = null; DataObjectAttributeRelationship rel = null; if (PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)) { if (ddReference != null) { if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) { relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, attributePrefix, keysOnly); return relationship; }//from w w w .jav a 2 s . c o m } if (dataObject == null) { try { dataObject = KRADUtils.createNewObjectFromClass(dataObjectClass); } catch (RuntimeException e) { // found interface or abstract class, just swallow exception and return a null relationship return null; } } // recurse down to the next object to find the relationship int nextObjectIndex = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(attributeName); if (nextObjectIndex == StringUtils.INDEX_NOT_FOUND) { nextObjectIndex = attributeName.length(); } String localPrefix = StringUtils.substring(attributeName, 0, nextObjectIndex); String localAttributeName = StringUtils.substring(attributeName, nextObjectIndex + 1); Object nestedObject = ObjectPropertyUtils.getPropertyValue(dataObject, localPrefix); Class<?> nestedClass = null; if (nestedObject == null) { nestedClass = ObjectPropertyUtils.getPropertyType(dataObject, localPrefix); } else { nestedClass = nestedObject.getClass(); } String fullPrefix = localPrefix; if (StringUtils.isNotBlank(attributePrefix)) { fullPrefix = attributePrefix + "." + localPrefix; } relationship = getDataObjectRelationship(nestedObject, nestedClass, localAttributeName, fullPrefix, keysOnly, supportsLookup, supportsInquiry); return relationship; } // non-nested reference, get persistence relationships first int maxSize = Integer.MAX_VALUE; if (isPersistable(dataObjectClass)) { DataObjectMetadata metadata = dataObjectService.getMetadataRepository().getMetadata(dataObjectClass); DataObjectRelationship dataObjectRelationship = metadata.getRelationship(attributeName); if (dataObjectRelationship != null) { List<DataObjectAttributeRelationship> attributeRelationships = dataObjectRelationship .getAttributeRelationships(); for (DataObjectAttributeRelationship dataObjectAttributeRelationship : attributeRelationships) { if (classHasSupportedFeatures(dataObjectRelationship.getRelatedType(), supportsLookup, supportsInquiry)) { maxSize = attributeRelationships.size(); relationship = transformToDeprecatedDataObjectRelationship(dataObjectClass, attributeName, attributePrefix, dataObjectRelationship.getRelatedType(), dataObjectAttributeRelationship); break; } } } } else { ModuleService moduleService = kualiModuleService.getResponsibleModuleService(dataObjectClass); if (moduleService != null && moduleService.isExternalizable(dataObjectClass)) { relationship = getRelationshipMetadata(dataObjectClass, attributeName, attributePrefix); if ((relationship != null) && classHasSupportedFeatures(relationship.getRelatedClass(), supportsLookup, supportsInquiry)) { return relationship; } else { return null; } } } if (ddReference != null && ddReference.getPrimitiveAttributes().size() < maxSize) { if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) { relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, null, keysOnly); } } return relationship; }