List of usage examples for org.apache.commons.lang3 StringUtils length
public static int length(final CharSequence cs)
From source file:org.blocks4j.reconf.client.setup.DatabaseURL.java
private static String getSecretKey(int keySize) { String key = LocalHostname.getName(); int missing = keySize - StringUtils.length(key); if (missing == 0) { return key; }//from w ww . j a v a2 s. co m if (missing < 0) { return StringUtils.substring(key, 0, keySize); } return key + StringUtils.repeat("#", missing); }
From source file:org.broadleafcommerce.openadmin.server.service.persistence.validation.FieldLengthValidator.java
@Override public PropertyValidationResult validate(Entity entity, Serializable instance, Map<String, FieldMetadata> entityFieldMetadata, BasicFieldMetadata propertyMetadata, String propertyName, String value) { boolean valid = true; String errorMessage = ""; if (propertyMetadata.getLength() != null) { valid = StringUtils.length(value) <= propertyMetadata.getLength(); }//from www . jav a 2 s .c o m if (!valid) { BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext(); MessageSource messages = context.getMessageSource(); errorMessage = messages.getMessage("fieldLengthValidationFailure", new Object[] { propertyMetadata.getLength(), StringUtils.length(value) }, context.getJavaLocale()); } return new PropertyValidationResult(valid, errorMessage); }
From source file:org.brunocvcunha.instagram4j.requests.InstagramEditProfileRequest.java
@Builder private InstagramEditProfileRequest(String biography, String fullName, String phone, String website, String username, String email, InstagramUserGenderEnum gender) { if (StringUtils.length(biography) > 150) { throw new IllegalArgumentException("biography cannot be longer than 150 chars."); }//from w w w. j a va 2 s . c o m if (StringUtils.isEmpty(username)) { throw new IllegalArgumentException("username cannot be empty."); } this.biography = biography; this.fullName = fullName; this.phone = phone; this.website = website; this.username = username; this.email = email; this.gender = gender; }
From source file:org.cryptomator.ui.InitializeController.java
public void usernameFieldDidChange(ObservableValue<? extends String> property, String oldValue, String newValue) {// w ww.j a v a 2 s . c o m if (StringUtils.length(newValue) > MAX_USERNAME_LENGTH) { usernameField.setText(newValue.substring(0, MAX_USERNAME_LENGTH)); } passwordField.setDisable(StringUtils.isEmpty(newValue)); }
From source file:org.eclipse.hawkbit.ui.common.UserDetailsFormatter.java
private static String trimAndFormatDetail(final String formatString, final int expectedDetailLength) { final String detail = StringUtils.defaultIfEmpty(formatString, ""); final String trimmedDetail = StringUtils.substring(detail, 0, expectedDetailLength); if (StringUtils.length(detail) > expectedDetailLength) { return trimmedDetail + TRIM_APPENDIX; }//from w ww . ja v a2 s . c om return trimmedDetail; }
From source file:org.finra.herd.service.helper.DefaultNotificationMessageBuilderTest.java
@Test public void testBuildBusinessObjectDataStatusChangeMessagesWithXmlPayloadWithMessageHeaders() throws Exception { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createTestValidBusinessObjectData(SUBPARTITION_VALUES, NO_ATTRIBUTE_DEFINITIONS, NO_ATTRIBUTES); // Get a business object data key. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectDataEntity); // Create message header keys. final String MESSAGE_HEADER_KEY_ENVIRONMENT = "environment"; final String MESSAGE_HEADER_KEY_MESSAGE_TYPE = "messageType"; final String MESSAGE_HEADER_KEY_MESSAGE_VERSION = "messageVersion"; final String MESSAGE_HEADER_KEY_SOURCE_SYSTEM = "sourceSystem"; final String MESSAGE_HEADER_KEY_MESSAGE_ID = "messageId"; final String MESSAGE_HEADER_KEY_USER_ID = "userId"; // Create message header definitions. List<MessageHeaderDefinition> messageHeaderDefinitions = new ArrayList<>(); messageHeaderDefinitions/*from w w w .jav a 2 s . c om*/ .add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_ENVIRONMENT, "$herd_environment")); messageHeaderDefinitions.add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_MESSAGE_TYPE, MESSAGE_TYPE)); messageHeaderDefinitions .add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_MESSAGE_VERSION, MESSAGE_VERSION)); messageHeaderDefinitions.add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_SOURCE_SYSTEM, SOURCE_SYSTEM)); messageHeaderDefinitions.add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_MESSAGE_ID, "$uuid")); messageHeaderDefinitions.add(new MessageHeaderDefinition(MESSAGE_HEADER_KEY_USER_ID, "$username")); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity .setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS .getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions( Arrays.asList(new NotificationMessageDefinition(MESSAGE_TYPE, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_XML, messageHeaderDefinitions))))); configurationDao.saveAndRefresh(configurationEntity); // Build the notification message List<NotificationMessage> result = defaultNotificationMessageBuilder .buildBusinessObjectDataStatusChangeMessages(businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(6, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); businessObjectDataServiceTestHelper.validateBusinessObjectDataStatusChangeMessageWithXmlPayload( MESSAGE_TYPE, MESSAGE_DESTINATION, businessObjectDataKey, businessObjectDataEntity.getId(), HerdDaoSecurityHelper.SYSTEM_USER, BDATA_STATUS, BDATA_STATUS_2, NO_ATTRIBUTES, Arrays.asList( new MessageHeader(MESSAGE_HEADER_KEY_ENVIRONMENT, configurationHelper.getProperty(ConfigurationValue.HERD_ENVIRONMENT)), new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_TYPE, MESSAGE_TYPE), new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_VERSION, MESSAGE_VERSION), new MessageHeader(MESSAGE_HEADER_KEY_SOURCE_SYSTEM, SOURCE_SYSTEM), new MessageHeader(MESSAGE_HEADER_KEY_MESSAGE_ID, uuid), new MessageHeader(MESSAGE_HEADER_KEY_USER_ID, HerdDaoSecurityHelper.SYSTEM_USER)), result.get(0)); }
From source file:org.finra.herd.service.helper.DefaultNotificationMessageBuilderTest.java
/** * Validates a business object data status change notification message with JSON payload. * * @param expectedMessageType the expected message type * @param expectedMessageDestination the expected message destination * @param expectedBusinessObjectDataKey the expected business object data key * @param expectedNewBusinessObjectDataStatus the expected new business object data status * @param expectedOldBusinessObjectDataStatus the expected old business object data status * @param expectedBusinessObjectDataAttributes the list of expected business object data attributes * @param expectedMessageHeaders the list of expected message headers * @param notificationMessage the notification message to be validated *///from w w w . j ava 2s. co m private void validateBusinessObjectDataStatusChangeMessageWithJsonPayload(String expectedMessageType, String expectedMessageDestination, BusinessObjectDataKey expectedBusinessObjectDataKey, String expectedNewBusinessObjectDataStatus, String expectedOldBusinessObjectDataStatus, List<Attribute> expectedBusinessObjectDataAttributes, List<MessageHeader> expectedMessageHeaders, NotificationMessage notificationMessage) throws IOException { assertNotNull(notificationMessage); assertEquals(expectedMessageType, notificationMessage.getMessageType()); assertEquals(expectedMessageDestination, notificationMessage.getMessageDestination()); BusinessObjectDataStatusChangeJsonMessagePayload businessObjectDataStatusChangeJsonMessagePayload = jsonHelper .unmarshallJsonToObject(BusinessObjectDataStatusChangeJsonMessagePayload.class, notificationMessage.getMessageText()); assertEquals(StringUtils.length(businessObjectDataStatusChangeJsonMessagePayload.eventDate), StringUtils.length(HerdDateUtils.now().toString())); assertEquals(expectedBusinessObjectDataKey, businessObjectDataStatusChangeJsonMessagePayload.businessObjectDataKey); assertEquals(expectedNewBusinessObjectDataStatus, businessObjectDataStatusChangeJsonMessagePayload.newBusinessObjectDataStatus); assertEquals(expectedOldBusinessObjectDataStatus, businessObjectDataStatusChangeJsonMessagePayload.oldBusinessObjectDataStatus); assertEquals(CollectionUtils.size(expectedBusinessObjectDataAttributes), CollectionUtils.size(businessObjectDataStatusChangeJsonMessagePayload.attributes)); if (CollectionUtils.isNotEmpty(expectedBusinessObjectDataAttributes)) { for (Attribute expectedAttribute : expectedBusinessObjectDataAttributes) { assertTrue(businessObjectDataStatusChangeJsonMessagePayload.attributes .containsKey(expectedAttribute.getName())); assertEquals(expectedAttribute.getValue(), businessObjectDataStatusChangeJsonMessagePayload.attributes .get(expectedAttribute.getName())); } } assertEquals(expectedMessageHeaders, notificationMessage.getMessageHeaders()); }
From source file:org.finra.herd.service.helper.notification.BusinessObjectDataStatusChangeMessageBuilderTest.java
@Test public void testBuildBusinessObjectDataStatusChangeMessagesJsonPayload() throws Exception { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createTestValidBusinessObjectData(SUBPARTITION_VALUES, NO_ATTRIBUTE_DEFINITIONS, NO_ATTRIBUTES); // Get a business object data key. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectDataEntity); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity//from ww w .j av a 2s . c o m .setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS .getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions( Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectDataStatusChangeMessageBuilder.buildNotificationMessages( new BusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2)); // Validate the notification message. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateBusinessObjectDataStatusChangeMessageWithJsonPayload(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2, NO_ATTRIBUTES, getExpectedMessageHeaders(uuid), result.get(0)); }
From source file:org.finra.herd.service.helper.notification.BusinessObjectDataStatusChangeMessageBuilderTest.java
@Test public void testBuildBusinessObjectDataStatusChangeMessagesXmlPayloadAndMessageHeaders() throws Exception { // Create a business object data entity. BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataServiceTestHelper .createTestValidBusinessObjectData(SUBPARTITION_VALUES, NO_ATTRIBUTE_DEFINITIONS, NO_ATTRIBUTES); // Get a business object data key. BusinessObjectDataKey businessObjectDataKey = businessObjectDataHelper .getBusinessObjectDataKey(businessObjectDataEntity); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity//w w w .ja v a 2 s. co m .setKey(ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DATA_STATUS_CHANGE_MESSAGE_DEFINITIONS .getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions( Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, BUSINESS_OBJECT_DATA_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_XML, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectDataStatusChangeMessageBuilder.buildNotificationMessages( new BusinessObjectDataStatusChangeNotificationEvent(businessObjectDataKey, BDATA_STATUS, BDATA_STATUS_2)); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); businessObjectDataServiceTestHelper.validateBusinessObjectDataStatusChangeMessageWithXmlPayload( MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, businessObjectDataKey, businessObjectDataEntity.getId(), HerdDaoSecurityHelper.SYSTEM_USER, BDATA_STATUS, BDATA_STATUS_2, NO_ATTRIBUTES, getExpectedMessageHeaders(uuid), result.get(0)); }
From source file:org.finra.herd.service.helper.notification.BusinessObjectDefinitionDescriptionSuggestionChangeMessageBuilderTest.java
@Test public void testBuildBusinessObjectDefinitionDescriptionSuggestionChangeMessages() throws Exception { // Create a namespace entity. NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(BDEF_NAMESPACE); // Create user namespace authorisations with user ids in reverse order and with WRITE and WRITE_DESCRIPTIVE_CONTENT namespace permissions. userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(USER_ID_3, namespaceEntity, Lists.newArrayList(NamespacePermissionEnum.WRITE)); userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(USER_ID_2, namespaceEntity, Lists.newArrayList(NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT)); // Create a business object definition description suggestion key. BusinessObjectDefinitionDescriptionSuggestionKey businessObjectDefinitionDescriptionSuggestionKey = new BusinessObjectDefinitionDescriptionSuggestionKey( BDEF_NAMESPACE, BDEF_NAME, USER_ID); // Create a business object definition description suggestion. BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion = new BusinessObjectDefinitionDescriptionSuggestion( ID, businessObjectDefinitionDescriptionSuggestionKey, DESCRIPTION_SUGGESTION, BusinessObjectDefinitionDescriptionSuggestionStatusEntity.BusinessObjectDefinitionDescriptionSuggestionStatuses.PENDING .name(),/*from w w w .ja v a 2s . co m*/ CREATED_BY, CREATED_ON); // Override configuration. ConfigurationEntity configurationEntity = new ConfigurationEntity(); configurationEntity.setKey( ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_MESSAGE_DEFINITIONS .getKey()); configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions( Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE, getMessageHeaderDefinitions()))))); configurationDao.saveAndRefresh(configurationEntity); // Build a notification message. List<NotificationMessage> result = businessObjectDefinitionDescriptionSuggestionChangeMessageBuilder .buildNotificationMessages(new BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent( businessObjectDefinitionDescriptionSuggestion, UPDATED_BY, UPDATED_ON, namespaceEntity.getCode())); // Validate the results. assertEquals(1, CollectionUtils.size(result)); assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders())); String uuid = result.get(0).getMessageHeaders().get(4).getValue(); assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid)); validateBusinessObjectDefinitionDescriptionSuggestionChangeMessage(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION, businessObjectDefinitionDescriptionSuggestion, UPDATED_BY, UPDATED_ON.toString(), Lists.newArrayList(CREATED_BY, USER_ID_2, USER_ID_3), String.format("https://udc.dev.finra.org/data-entities/%s/%s", BDEF_NAMESPACE, BDEF_NAME), getExpectedMessageHeaders(uuid), result.get(0)); }