/** * This method is used during debugging to dump the contents of the error map, including the key names. It is not * used by the * application in normal circumstances at all. */ protected void showErrorMap() { if (GlobalVariables.getMessageMap().hasNoErrors()) { return; } for (Iterator i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext(); ) { Map.Entry e = (Map.Entry) i.next(); AutoPopulatingList errorList = (AutoPopulatingList) e.getValue(); for (Iterator j = errorList.iterator(); j.hasNext(); ) { ErrorMessage em = (ErrorMessage) j.next(); if (em.getMessageParameters() == null) { LOG.error(e.getKey().toString() + " = " + em.getErrorKey()); } else { LOG.error(e.getKey().toString() + " = " + em.getErrorKey() + " : " + Arrays.toString(em.getMessageParameters())); } } } }
private void copyAllMessagesHelper(Map<String, AutoPopulatingList<ErrorMessage>> sourceMessages, String type, MessageMap destMap) { for (String key : sourceMessages.keySet()) { AutoPopulatingList<ErrorMessage> messages = sourceMessages.get(key); if (messages != null) { for (Object o : messages) { ErrorMessage message = (ErrorMessage) o; if ("info".equals(type)) { destMap.putInfoWithoutFullErrorPath(key, message.getErrorKey(), message.getMessageParameters()); } else if ("warning".equals(type)) { destMap.putWarningWithoutFullErrorPath(key, message.getErrorKey(), message.getMessageParameters()); } else if ("error".equals(type)) { destMap.putErrorWithoutFullErrorPath(key, message.getErrorKey(), message.getMessageParameters()); } else { throw new IllegalArgumentException(); } } } } }
/** * A stub method as placeholder for future Contact Validation * * @param document MaintenanceDocument instance * @return boolean false or true */ private boolean processContactValidation(MaintenanceDocument document) { boolean valid = true; int i = 0; for (VendorContact contact : newVendor.getVendorContacts()) { String errorPath = MAINTAINABLE_ERROR_PREFIX + VendorPropertyConstants.VENDOR_CONTACT + "[" + i + "]"; GlobalVariables.getMessageMap().addToErrorPath(errorPath); this.getDictionaryValidationService().validateBusinessObject(contact); Map<String, AutoPopulatingList<ErrorMessage>> errors = GlobalVariables.getMessageMap().getErrorMessages(); if ((errors != null ) && (!errors.isEmpty())) { valid = false; } i++; GlobalVariables.getMessageMap().clearErrorPath(); } return valid; }
/** * * This method is used during debugging to dump the contents of the error map, including the key names. It is not used by the * application in normal circumstances at all. * */ private void showMessageMap() { if (GlobalVariables.getMessageMap().hasErrors()) { return; } Set<String> errorMapKeys = ((Map<String, String>) GlobalVariables.getMessageMap()).keySet(); AutoPopulatingList<ErrorMessage> errorMapEntry; for (String errorMapKey : errorMapKeys) { errorMapEntry = (AutoPopulatingList<ErrorMessage>) (GlobalVariables.getMessageMap()).getMessages(errorMapKey); for (ErrorMessage errorMessage : errorMapEntry) { if (errorMessage.getMessageParameters() == null) { LOG.error("[" + errorMapKey + "] " + errorMessage.getErrorKey()); } else { LOG.error("[" + errorMapKey + "] " + errorMessage.getErrorKey() + " == " + parseStringArray(errorMessage.getMessageParameters())); } } } }
/** * This method is used during debugging to dump the contents of the error map, including the key names. It is not * used by the * application in normal circumstances at all. */ protected void showErrorMap() { if (GlobalVariables.getMessageMap().hasNoErrors()) { return; } for (Iterator i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext(); ) { Map.Entry e = (Map.Entry) i.next(); AutoPopulatingList errorList = (AutoPopulatingList) e.getValue(); for (Iterator j = errorList.iterator(); j.hasNext(); ) { ErrorMessage em = (ErrorMessage) j.next(); if (em.getMessageParameters() == null) { LOG.error(e.getKey().toString() + " = " + em.getErrorKey()); } else { LOG.error(e.getKey().toString() + " = " + em.getErrorKey() + " : " + em.getMessageParameters().toString()); } } } }
public SerializerServiceBase() { serializationStates = new ThreadLocal<SerializationState>(); evaluators = new ThreadLocal<PropertySerializabilityEvaluator>(); xstream = new XStream(new ProxyAndStateAwareJavaReflectionProvider()); xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() )); try { Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl"); xstream.addDefaultImplementation(ArrayList.class, objListProxyClass); xstream.addDefaultImplementation(AutoPopulatingList.class, objListProxyClass); } catch ( Exception ex ) { // Do nothing - this will blow if the OJB class does not exist, which it won't in some installs } xstream.registerConverter(new AutoPopulatingListConverter(xstream.getMapper())); xstream.registerConverter(new DateTimeConverter()); }
/** * Test that message text is correctly retrieved for a validation message specified by namespace and * message key */ @Test public void testRetrieveMessage_namespaceKey() throws Exception { ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setNamespaceCode("KR-NS"); errorMessage.setErrorKey("testErrorKey"); messageMap.putError("field1", errorMessage); AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1"); assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size()); ErrorMessage message = fieldErrors.get(0); String messageText = KRADUtils.getMessageText(message, true); assertEquals("Message for field1 is not correct", "Error on field1", messageText); }
/** * Test that message text is correctly retrieved for a validation message specified by namespace, * component, and message key */ @Test public void testRetrieveMessage_componentKey() throws Exception { ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setNamespaceCode("KR-NS"); errorMessage.setComponentCode("GeneralGroup"); errorMessage.setErrorKey("testErrorKey"); messageMap.putError("field1", errorMessage); AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1"); assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size()); ErrorMessage message = fieldErrors.get(0); String messageText = KRADUtils.getMessageText(message, true); assertEquals("Message for field1 is not correct", "Error on field1", messageText); }
/** * Gets all the messages from the list of lists passed in (which are * lists of ErrorMessages associated to the key) and uses the configuration * service to get the message String associated. This will also combine * error messages per a field if that option is turned on. If * displayFieldLabelWithMessages is turned on, it will also find the label * by key passed in. * * @param view * @param key * @param lists * @return */ private List<String> getMessages(View view, String key, List<AutoPopulatingList<ErrorMessage>> lists) { List<String> result = new ArrayList<String>(); for (List<ErrorMessage> errorList : lists) { if (errorList != null && StringUtils.isNotBlank(key)) { for (ErrorMessage e : errorList) { String message = KRADUtils.getMessageText(e, true); message = MessageStructureUtils.translateStringMessage(message); result.add(message); } } } return result; }
/** * Takes one message map and merges it into another. Makes sure there are no duplicates. * * @param messagesFrom * @param messagesTo */ public void merge(Map<String, AutoPopulatingList<ErrorMessage>> messagesFrom, Map<String, AutoPopulatingList<ErrorMessage>> messagesTo) { for (String key : messagesFrom.keySet()) { if (messagesTo.containsKey(key)) { // now we need to merge the messages AutoPopulatingList<ErrorMessage> tal = messagesFrom.get(key); AutoPopulatingList<ErrorMessage> parentList = messagesTo.get(key); for (Object o : tal) { if (!parentList.contains(o)) { parentList.add((ErrorMessage) o); } } } else { messagesTo.put(key, messagesFrom.get(key)); } } }
/** * @return true if the given messageKey is associated with some property in this ErrorMap */ public boolean containsMessageKey(String messageKey) { ErrorMessage foundMessage = null; if (!hasNoErrors()) { for (Iterator<Map.Entry<String, AutoPopulatingList<ErrorMessage>>> i = getAllPropertiesAndErrors().iterator(); (foundMessage == null) && i.hasNext(); ) { Map.Entry<String, AutoPopulatingList<ErrorMessage>> e = i.next(); AutoPopulatingList<ErrorMessage> entryErrorList = e.getValue(); for (Iterator<ErrorMessage> j = entryErrorList.iterator(); j.hasNext(); ) { ErrorMessage em = j.next(); if (messageKey.equals(em.getErrorKey())) { foundMessage = em; } } } } return (foundMessage != null); }
/** * Gets a list of lists that represent errors that matched by the * propertyName passed in (multiple lists because the wildcard can match * multiple keys). If wildcard is true, the propertyName ends with a * wildcard character. Otherwise, it will only match on the single key and * return a list with one list * * @param propertyName * @param allowWildcard * @return */ public List<AutoPopulatingList<ErrorMessage>> getErrorMessagesForProperty(String propertyName, boolean allowWildcard) { List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); if (allowWildcard) { boolean wildcard = false; if (propertyName.endsWith("*")) { wildcard = true; propertyName = propertyName.substring(0, propertyName.length() - 1); } for (Iterator<String> keys = errorMessages.keySet().iterator(); keys.hasNext(); ) { String key = keys.next(); if (!wildcard && propertyName.equals(key)) { foundMessages.add(errorMessages.get(key)); break; } else if (wildcard && key.startsWith(propertyName)) { foundMessages.add(errorMessages.get(key)); } } } else { foundMessages.add(getErrorMessagesForProperty(propertyName)); } return foundMessages; }
/** * Gets a list of lists that represent warnings that matched by the * propertyName passed in (multiple lists because the wildcard can match * multiple keys). If wildcard is true, the propertyName ends with a * wildcard character. Otherwise, it will only match on the single key and * return a list with one list. * * @param propertyName * @param allowWildcard * @return */ public List<AutoPopulatingList<ErrorMessage>> getWarningMessagesForProperty(String propertyName, boolean allowWildcard) { List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); if (allowWildcard) { boolean wildcard = false; if (propertyName.endsWith("*")) { wildcard = true; propertyName = propertyName.substring(0, propertyName.length() - 1); } for (Iterator<String> keys = warningMessages.keySet().iterator(); keys.hasNext(); ) { String key = keys.next(); if (!wildcard && propertyName.equals(key)) { foundMessages.add(warningMessages.get(key)); break; } else if (wildcard && key.startsWith(propertyName)) { foundMessages.add(warningMessages.get(key)); } } } else { foundMessages.add(getWarningMessagesForProperty(propertyName)); } return foundMessages; }
/** * Gets a list of lists that represent info messages that matched by the * propertyName passed in (multiple lists because the wildcard can match * multiple keys). If wildcard is true, the propertyName ends with a * wildcard character. If it is false, it will only match on the single key * and return a list with one list. * * @param propertyName * @param allowWildcard * @return */ public List<AutoPopulatingList<ErrorMessage>> getInfoMessagesForProperty(String propertyName, boolean allowWildcard) { List<AutoPopulatingList<ErrorMessage>> foundMessages = new ArrayList<AutoPopulatingList<ErrorMessage>>(); if (allowWildcard) { boolean wildcard = false; if (propertyName.endsWith("*")) { wildcard = true; propertyName = propertyName.substring(0, propertyName.length() - 1); } for (Iterator<String> keys = infoMessages.keySet().iterator(); keys.hasNext(); ) { String key = keys.next(); if (!wildcard && propertyName.equals(key)) { foundMessages.add(infoMessages.get(key)); break; } else if (wildcard && key.startsWith(propertyName)) { foundMessages.add(infoMessages.get(key)); } } } else { foundMessages.add(getInfoMessagesForProperty(propertyName)); } return foundMessages; }
/** * Test message parameters are being correctly added and associated with an error message. */ @Test public void testMessageParameters() { MessageMap testMap = new MessageMap(); testMap.putError("accountNbr", RiceKeyConstants.ERROR_INACTIVE, "Account Number"); testMap.putError("accountNbr", RiceKeyConstants.ERROR_REQUIRED, "Account Number"); // check duplicate message doesn't get added testMap.putError("accountNbr", RiceKeyConstants.ERROR_INACTIVE, "Account Number"); testMap.putError("chartCode", RiceKeyConstants.ERROR_REQUIRED, "Chart Code"); assertEquals(3, testMap.getErrorCount()); AutoPopulatingList errorMessages = testMap.getMessages("accountNbr"); assertEquals(2, errorMessages.size()); checkMessageParemeters(errorMessages, 0, RiceKeyConstants.ERROR_INACTIVE, new String[] { "Account Number" }); checkMessageParemeters(errorMessages, 1, RiceKeyConstants.ERROR_REQUIRED, new String[] { "Account Number" }); errorMessages = testMap.getMessages("chartCode"); assertEquals(1, errorMessages.size()); checkMessageParemeters(errorMessages, 0, RiceKeyConstants.ERROR_REQUIRED, new String[] { "Chart Code" }); }
public MessageMap() { errorPath = Collections.synchronizedList(new ArrayList<String>()); errorMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); warningMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); infoMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); growlMessages = Collections.synchronizedList(new AutoPopulatingList<GrowlMessage>(GrowlMessage.class)); }
public MessageMap(MessageMap messageMap) { this.errorPath = messageMap.errorPath; this.errorMessages = messageMap.errorMessages; this.warningMessages = messageMap.warningMessages; this.infoMessages = messageMap.infoMessages; growlMessages = Collections.synchronizedList(new AutoPopulatingList<GrowlMessage>(GrowlMessage.class)); }
/** * no args constructor that just initializes things for us */ @SuppressWarnings("unchecked") public KualiDocumentFormBase() { super(); instantiateDocument(); newNote = new Note(); this.editingMode = new HashMap(); //this.additionalScriptFiles = new AutoPopulatingList(String.class); this.additionalScriptFiles = new AutoPopulatingList<String>(String.class); // set the initial record for persons up newAdHocRoutePerson = new AdHocRoutePerson(); // set the initial record for workgroups up newAdHocRouteWorkgroup = new AdHocRouteWorkgroup(); // to make sure it posts back the correct time setFormatterType("document.documentHeader.note.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class); setFormatterType("document.documentHeader.note.attachment.finDocNotePostedDttmStamp", TimestampAMPMFormatter.class); //TODO: Chris - Notes: remove the above and change the below from boNotes when notes are finished //overriding note formatter to make sure they post back the full timestamp setFormatterType("document.documentHeader.boNote.notePostedTimestamp",TimestampAMPMFormatter.class); setFormatterType("document.documentBusinessObject.boNote.notePostedTimestamp",TimestampAMPMFormatter.class); setFormatterType("editingMode", NoOpStringFormatter.class); setFormatterType("editableAccounts", NoOpStringFormatter.class); setDocumentActions(new HashMap()); suppressAllButtons = false; initializeHeaderNavigationTabs(); }
public void setExtraButtons(List<ExtraButton> extraButtons) { if ( extraButtons instanceof AutoPopulatingList ) { this.extraButtons = extraButtons; } else { this.extraButtons.clear(); this.extraButtons.addAll( extraButtons ); } }
@Override public List<RoleResponsibilityActionBo> getRoleRspActions() { if (this.roleRspActions == null) { return new AutoPopulatingList<RoleResponsibilityActionBo>(RoleResponsibilityActionBo.class); } return this.roleRspActions; }
/** * This method... * @param map */ protected void removeRestrictedFieldChangedErrors(MessageMap map, String propertyKey) { AutoPopulatingList<ErrorMessage> errorMessages = map.getErrorMessagesForProperty(propertyKey); if(errorMessages!=null) { for(int i=0; i<errorMessages.size(); i++) { ErrorMessage eMessage = errorMessages.get(i); String errorKey = eMessage.getErrorKey(); if(errorKey.equals(KFSKeyConstants.ERROR_DOCUMENT_AUTHORIZATION_RESTRICTED_FIELD_CHANGED)) { errorMessages.remove(i); } } } }
/** * Asserts true if the specified ItemParserException reports the appropriate error message * with the expected parameters upon invalid numeric value for input item property. * * @param e the specified ItemParserException * @param propertyName the property name for the invalid property value * @param propertyValue the invalid property value */ private static void assertInvalidNumericValue( ItemParserException e, String propertyName, String propertyValue ) { assertEquals(e.getErrorKey(), ERROR_ITEMPARSER_ITEM_PROPERTY); String errorPath = PurapConstants.ITEM_TAB_ERRORS; String errorKey = ERROR_ITEMPARSER_INVALID_NUMERIC_VALUE; assertTrue(GlobalVariables.getMessageMap().containsMessageKey(errorKey)); AutoPopulatingList<ErrorMessage> params = GlobalVariables.getMessageMap().getMessages(errorPath); for (int i=0; i<params.size(); i++) { ErrorMessage errmsg = (ErrorMessage)params.get(i); if (errmsg.getErrorKey().equals(errorKey)) { assertEquals(errmsg.getMessageParameters()[0], propertyValue); assertEquals(errmsg.getMessageParameters()[1], propertyName); } } }
public void testValidatePaymentRequestDates_PastAndInitiatedDocument() throws Exception { DocumentService documentService = SpringContext.getBean(DocumentService.class); PaymentRequestService paymentRequestService = SpringContext.getBean(PaymentRequestService.class); // some date in the past Date yesterday = getDateFromOffsetFromToday(-1); assertFalse("Something is wrong with the test. Error map was not empty before document saving called", GlobalVariables.getMessageMap().hasErrors()); // rule 1: past pay dates are NOT allowed if the document has not been successfully saved or submitted yet PaymentRequestDocument document1 = (PaymentRequestDocument) documentService.getNewDocument(PaymentRequestDocument.class); document1.setPaymentRequestPayDate(yesterday); PaymentRequestPayDateNotPastValidation validation = (PaymentRequestPayDateNotPastValidation)validations.get("PaymentRequest-payDateNotPastValidation-test"); assertFalse( validation.validate(new AttributedDocumentEventBase("","", document1)) ); AutoPopulatingList<ErrorMessage> l = GlobalVariables.getMessageMap().getMessages("document.paymentRequestPayDate"); boolean correctError = false; for ( ErrorMessage m : l ) { if (PurapKeyConstants.ERROR_INVALID_PAY_DATE.equals(m.getErrorKey())) { correctError = true; break; } } assertTrue("Unable to find error message key '" + PurapKeyConstants.ERROR_INVALID_PAY_DATE + "'", correctError); GlobalVariables.getMessageMap().clearErrorMessages(); }
/** * Test that message text is correctly retrieved for a validation message specified with only the * message key */ @Test public void testRetrieveMessage_keyOnly() throws Exception { messageMap.putError("field1", "testErrorKey"); AutoPopulatingList<ErrorMessage> fieldErrors = messageMap.getErrorMessagesForProperty("field1"); assertEquals("Incorrect number of messages for field1", 1, fieldErrors.size()); ErrorMessage message = fieldErrors.get(0); String messageText = KRADUtils.getMessageText(message, true); assertEquals("Message for field1 is not correct", "Error on field1", messageText); }
/** * This method logs errors. */ protected void logErrors() { if (LOG.isInfoEnabled()) { if (GlobalVariables.getMessageMap().hasErrors()) { for (Iterator<Map.Entry<String, AutoPopulatingList<ErrorMessage>>> i = GlobalVariables.getMessageMap().getAllPropertiesAndErrors().iterator(); i.hasNext(); ) { Map.Entry<String, AutoPopulatingList<ErrorMessage>> e = i.next(); StringBuffer logMessage = new StringBuffer(); logMessage.append("[" + e.getKey() + "] "); boolean first = true; AutoPopulatingList<ErrorMessage> errorList = e.getValue(); for (Iterator<ErrorMessage> j = errorList.iterator(); j.hasNext(); ) { ErrorMessage em = j.next(); if (first) { first = false; } else { logMessage.append(";"); } logMessage.append(em); } LOG.info(logMessage); } } } }
public MessageMap(MessageMap messageMap) { this.errorPath = messageMap.errorPath; this.errorMessages = messageMap.errorMessages; this.warningMessages = messageMap.warningMessages; this.infoMessages = messageMap.infoMessages; growlMessages = new AutoPopulatingList<GrowlMessage>(GrowlMessage.class); }
/** * If any error messages with the key targetKey exist in this ErrorMap for the named property, those ErrorMessages * will be replaced with a new ErrorMessage with the given replaceKey and replaceParameters. * * @param propertyName name of the property to add error under * @param targetKey resource key used to retrieve the error text * @param withFullErrorPath true if you want the whole parent error path appended, false otherwise * @param replaceParameters zero or more string parameters for the displayed error message * @return true if the replacement occurred */ private boolean replaceError(String propertyName, String targetKey, boolean withFullErrorPath, String replaceKey, String... replaceParameters) { boolean replaced = false; if (StringUtils.isBlank(propertyName)) { throw new IllegalArgumentException("invalid (blank) propertyName"); } if (StringUtils.isBlank(targetKey)) { throw new IllegalArgumentException("invalid (blank) targetKey"); } if (StringUtils.isBlank(replaceKey)) { throw new IllegalArgumentException("invalid (blank) replaceKey"); } // check if we have previous errors for this property AutoPopulatingList<ErrorMessage> errorList = null; String propertyKey = getKeyPath(propertyName, withFullErrorPath); if (errorMessages.containsKey(propertyKey)) { errorList = errorMessages.get(propertyKey); // look for the specific targetKey for (int i = 0; i < errorList.size(); ++i) { ErrorMessage em = errorList.get(i); // replace matching messages if (em.getErrorKey().equals(targetKey)) { ErrorMessage rm = new ErrorMessage(replaceKey, replaceParameters); errorList.set(i, rm); replaced = true; } } } return replaced; }
private int getMessageCount(Map<String, AutoPopulatingList<ErrorMessage>> messageMap) { int messageCount = 0; for (Iterator<String> iter = messageMap.keySet().iterator(); iter.hasNext(); ) { String errorKey = iter.next(); List<ErrorMessage> errors = messageMap.get(errorKey); messageCount += errors.size(); } return messageCount; }