Package org.eurekastreams.commons.exceptions

Examples of org.eurekastreams.commons.exceptions.ValidationException


            String message = "Couldn't get bean info for " + instance.getClass();
            throw new RuntimeException(message, ie);
        }

        // if there are any cast/parse exceptions, add them to this
        ValidationException validationException = new ValidationException();

        for (PropertyDescriptor property : descriptors)
        {
            // some properties might not be passed in
            String propertyName = property.getName();
            if (!properties.containsKey(propertyName))
            {
                continue;
            }

            // some properties don't have setters
            Method setter = property.getWriteMethod();
            if (setter == null)
            {
                continue;
            }

            Serializable valueObj = properties.get(propertyName);

            // catch invocation-level exceptions at the same level
            // so we only need to do exception handling once
            try
            {
                // now you have a property, a setter, and a new value. Set it!

                // to add property types, put another block here for that type
                // cast or parse exceptions are added to the ValidationException
                // and returned as part of the validation result set

                // the reason you don't just call setter.invoke() is that
                // when the map comes in as a String/String map from a form,
                // the strings will need to be parsed before calling the setter
                // if the property type is a Long/Int/Date/etc

                if (property.getPropertyType().equals(String.class))
                {
                    String value = (String) valueObj;

                    // if empty string, should set to null for database
                    // (optional=true)
                    if ("".equals(value))
                    {
                        value = null;
                    }
                    setter.invoke(instance, value);
                    continue;
                }

                if (property.getPropertyType().equals(List.class))
                {
                    setter.invoke(instance, (List) valueObj);
                    continue;
                }
                if (property.getPropertyType().equals(HashMap.class))
                {
                    setter.invoke(instance, (HashMap) valueObj);
                    continue;
                }
                if (property.getPropertyType().equals(Set.class))
                {
                    setter.invoke(instance, (Set) valueObj);
                    continue;
                }
                if (property.getPropertyType().equals(boolean.class)
                        || property.getPropertyType().equals(Boolean.class))
                {
                    setter.invoke(instance, ((Boolean) valueObj).booleanValue());
                    continue;
                }
                if (property.getPropertyType().equals(Integer.class) || property.getPropertyType().equals(int.class))
                {
                    setter.invoke(instance, (Integer) valueObj);
                    continue;
                }
                if (property.getPropertyType().equals(float.class))
                {
                    setter.invoke(instance, ((Float) valueObj).floatValue());
                    continue;
                }
                if (property.getPropertyType().equals(Date.class))
                {
                    setter.invoke(instance, (Date) valueObj);
                    continue;
                }
                // TODO add more property types here
                // once our domain classes have more than just strings.

                validationException.addError(propertyName, "Type not found.");

                // TODO some of these exceptions I either can't get to
                // (because they're programmatically prevented above)
                // or I just plain don't know how to cause. These should be tested as well
            }
            catch (IllegalArgumentException e)
            {
                validationException.addError(propertyName, valueObj + " had an illegal argument");
            }
            catch (IllegalAccessException e)
            {
                validationException.addError(propertyName, valueObj + " couldn't be accessed");
            }
            catch (InvocationTargetException e)
            {
                validationException.addError(propertyName, valueObj + " couldn't be invoked");
            }
        }

        // hibernate would throw an exception on writing,
        // but if we do it manually we can re-wrap hibernate's validation info
        // in a more concise and gwt-friendly way
        ClassValidator validator = new ClassValidator(instance.getClass());
        InvalidValue[] invalidValues = validator.getInvalidValues(instance);

        for (InvalidValue invalidValue : invalidValues)
        {
            validationException.addError(invalidValue.getPropertyName(), invalidValue.getMessage());
        }

        // throw if we had any parse errors or constraints errors
        if (validationException.getErrors().size() > 0)
        {
            throw validationException;
        }
    }
View Full Code Here


    public void populate(final PluginDefinition inPluginDefinition,
            final String inPluginDefinitionUrl)
    {
        boolean hasFeature = false;

        ValidationException ve = new ValidationException();

        String errorMessage = "";

        // ensure the gadget is a plugin type.
        try
        {
            hasFeature = checkForRequiredFeature(inPluginDefinitionUrl);
        }
        catch (Exception ex)
        {
            log.debug(CANT_FIND_PLUGIN, ex);
            ve.addError("url", CANT_FIND_PLUGIN);
            throw ve;
        }

        final Map<String, GeneralGadgetDefinition> gadgetDefs = new HashMap<String, GeneralGadgetDefinition>();
        gadgetDefs.put(inPluginDefinitionUrl, inPluginDefinition);

        log.info("Fetching gadget data");

        try
        {
            List<GadgetMetaDataDTO> meta = metaDataFetcher.getGadgetsMetaData(gadgetDefs);

            if (meta.size() > 0)
            {
                /*
                 * These two fields are the only fields being populated because the other values are populate via
                 * Shindig on each ui request.
                 */

                GadgetMetaDataDTO metadata = meta.get(0);

                for (UserPrefDTO up : metadata.getUserPrefs())
                {
                    if ("updateFrequency".equals(up.getName()))
                    {
                        try
                        {
                            Long updateFreq = Long.parseLong(up.getDefaultValue());
                            inPluginDefinition.setUpdateFrequency(updateFreq);
                        }
                        catch (Exception ex)
                        {
                            errorMessage += UPDATE_FREQUENCY_ERROR;
                        }
                    }
                    else if ("objectType".equals(up.getName()))
                    {
                        try
                        {
                            inPluginDefinition.setObjectType(BaseObjectType.valueOf(up.getDefaultValue()));
                        }
                        catch (Exception ex)
                        {
                            errorMessage += OBJECTTYPE_ERROR;
                        }
                    }
                }
            }

            // Check for all required elements
            if (!hasFeature)
            {
                errorMessage += FEATURE_ERROR;
            }

            // add see if a error message was created. If so add it as a validation exceptions. If not check for
            // defaults.
            if (!errorMessage.equals(""))
            {
                ve.addError("url", errorMessage);

            }
            else
            {
                if (inPluginDefinition.getObjectType() == null)
                {
                    inPluginDefinition.setObjectType(defaultObjectType);
                }
                if (inPluginDefinition.getUpdateFrequency() == null)
                {
                    inPluginDefinition.setUpdateFrequency(defaultUpdateFrequency);
                }
            }

            // Check if any errors exist
            if (!ve.getErrors().isEmpty())
            {
                throw ve;
            }

        }
        catch (ValidationException ve2)
        {
            throw ve2;
        }
        catch (Exception ex)
        {
            ve.addError("url", "Error retreiving plugin data.");
            log.debug(ex.fillInStackTrace());
            throw ve;
        }

    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void validate(final ActivityDTO inActivity)
    {
        ValidationException ve = new ValidationException();

        //Actor is not validated because it is supplied by the action.
       
        if (inActivity.getOriginalActor() != null
                && inActivity.getOriginalActor().getUniqueIdentifier() != null
                && inActivity.getOriginalActor().getUniqueIdentifier().length() > 0)
        {
            ve.addError("OriginalActor", "Must not be included for Post verbs.");
        }
       
        if (!ve.getErrors().isEmpty())
        {
            throw ve;
        }
    }
View Full Code Here

    @Override
    public void persist(final TaskHandlerActionContext<PrincipalActionContext> inActionContext,
            final Map<String, Serializable> inFields, final DomainGroup inGroup) throws Exception
    {
        final Principal principal = inActionContext.getActionContext().getPrincipal();
        ValidationException ve = new ValidationException();
        String creatorUserName = principal.getAccountId();
        final Long creatorPersonId = principal.getId();
        SystemSettings settings = getSystemSettingsMapper.execute(null);

        // Verify that group with given short name doesn't already exist.
        if (getGroupMapper().findByShortName(inGroup.getShortName()) != null)
        {
            ve.addError(SHORTNAME_KEY, DUP_SHORTNAME_MSG);
        }

        // Verify that group has on coordinator.
        if (inGroup.getCoordinators().isEmpty())
        {
            ve.addError("coordinators", "Group must have at least one coordinator");
        }

        if (!ve.getErrors().isEmpty())
        {
            throw ve;
        }

        // if the system requires approval to create groups, set the pending state to true.
View Full Code Here

       
        //If result is found for url and it's not the current item being updated,
        //throw exception
        if (inUseGalleryItem != null && (inUseGalleryItem.getUUID() != inGalleryItem.getUUID()))
        {
            ValidationException ve = new ValidationException();
            ve.addError(URL_KEY, "Url has already been uploaded to Eureka");
            throw ve;
        }
        galleryItemMapper.flush();
    }
View Full Code Here

     */
    public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> context)
    {
        HashMap<String, Serializable> values = (HashMap<String, Serializable>) context.getActionContext().getParams();

        ValidationException exception = new ValidationException();

        // Loop through and see if any key/values are required through the use of the
        // REQUIRED: prefix.
        for (String key : values.keySet())
        {
            if (key.contains("REQUIRED:"))
            {
                String keyLookup = key.split("REQUIRED:")[1];
                if (!values.containsKey(keyLookup) || values.get(keyLookup) == null
                        || (values.get(keyLookup) instanceof String && ((String) values.get(keyLookup)).equals("")))
                {
                    exception.addError(keyLookup, (String) values.get(key));
                }
            }
        }

        // Make sure they checked the TOS.
        if (!(Boolean) values.get("EUREKA:TOS"))
        {
            exception.addError("EUREKA:TOS", "In order to use this plugin you must agree to the terms of use.");
        }

        // If you found any errors, error.
        if (exception.getErrors().size() > 0)
        {
            throw exception;
        }

        String group = "";
View Full Code Here

               log.error(msg);
               JSONObject validationErrors = new JSONObject();
               validationErrors.put(VALIDATION_ERRORS_KEY, msg);
               getAdaptedResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               getAdaptedResponse().setEntity(validationErrors.toString(), MediaType.APPLICATION_JSON);
               throw new ValidationException();
           }
        }
    }
View Full Code Here

        for (Object entryObject : syndFeed.getEntries())
        {
            SyndEntry entry = (SyndEntry) entryObject;
            if (entry.getUri() == null || entry.getUri().trim().isEmpty())
            {
                throw new ValidationException("Invalid feed.  Every feed entry must contain a URI.");
            }
        }

        return syndFeed.getTitle();
    }
View Full Code Here

        // get the entity whose stream to post to
        DomainMapper<Long, String> uniqueIdDAO = uniqueIdDAOs.get(request.getEntityType());
        if (uniqueIdDAO == null)
        {
            throw new ValidationException("Request to post to unsupported stream type " + request.getEntityType());
        }
        String uniqueId = uniqueIdDAO.execute(request.getEntityId());

        // split the text
        List<String> pieces = textSplitter.split(request.getText());
        if (pieces.isEmpty())
        {
            throw new ValidationException("Text to post must not be empty.");
        }

        // post the activity
        ActivityDTO activityToPost = new ActivityDTO();
        activityToPost.setBaseObjectType(BaseObjectType.NOTE);
View Full Code Here

TOP

Related Classes of org.eurekastreams.commons.exceptions.ValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.