Package org.eurekastreams.commons.exceptions

Examples of org.eurekastreams.commons.exceptions.ValidationException


        {
            valDecorator.validate(map, errors);
        }
        else if (!errors.isEmpty())
        {
            ValidationException ve = new ValidationException();
            for (String errorKey : errors.keySet())
            {
                ve.addError(errorKey, errors.get(errorKey));
            }
            throw ve;
        }
    }
View Full Code Here


            log.debug("Success validating xml at: " + galleryItemUrl);
        }
        catch (Exception e)
        {
            log.error("Validation for gadget definition failed.", e);
            ValidationException ve = new ValidationException();
            ve.addError(URL_KEY, "Valid url is required");
            throw ve;
        }
        finally
        {
            try
View Full Code Here

     *             on validation error.
     */
    @Override
    public void validate(final PrincipalActionContext inActionContext) throws ValidationException
    {
        ValidationException valEx = new ValidationException();

        Stream stream = (Stream) inActionContext.getParams();

        JSONObject object = null;
        try
        {
            object = JSONObject.fromObject(stream.getRequest());
        }
        catch (JSONException ex)
        {
            valEx.addError("stream", "Malformed JSON. Try again later.");
            throw valEx;
        }

        if (stream.getName() == null || stream.getName().length() == 0)
        {
            valEx.addError("name", "Stream must have a name.");
            throw valEx;
        }

        JSONObject query = object.getJSONObject("query");

        for (Object key : query.keySet())
        {
            String keyStr = (String) key;

            try
            {
                JSONArray arr = query.getJSONArray(keyStr);

                if (arr.size() == 0)
                {
                    valEx.addError("stream", "Add at least one stream");
                    throw valEx;
                }
                else if (arr.size() > MAX_STREAMS)
                {
                    valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS);
                    throw valEx;
                }
            }
            catch (JSONException ex)
            {
View Full Code Here

    @Override
    public void validate(final PrincipalActionContext inActionContext) throws ValidationException
    {
        SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams();

        ValidationException vex = new ValidationException();

        if (inRequest.getTargetUniqueId().length() <= 0)
        {
            vex.addError("FollowerAndTarget", "This action requires a target unique id");
            logger.error("Validation error - " + vex.getErrors().get("FollowerAndTarget"));
            // if this occurs, throw the error now, no point continuing since the following calls will fail.
            throw vex;
        }

        if (inRequest.getFollowerStatus().equals(Follower.FollowerStatus.NOTSPECIFIED))
        {
            vex.addError("FollowingStatus", "This action does not accept setting FollowerStatus of NOTSPECIFIED");
            logger.error("Validation error - " + vex.getErrors().get("FollowingStatus"));
            throw vex;
        }

        decoratorValidationStrategy.validate(inActionContext);
View Full Code Here

        /*
         * If theme is still null, throw an exception, something went wrong, most likely a bad UUID.
         */
        if (null == theme)
        {
            throw new ValidationException("Unable to instantiate theme.");
        }

        inActionContext.getState().put("THEME", theme);
    }
View Full Code Here

        GetGalleryItemsRequest currentRequest = (GetGalleryItemsRequest) inActionContext.getParams();

        if (!currentRequest.getSortCriteria().equals(RECENT_SORT_CRITERIA)
          && !currentRequest.getSortCriteria().equals(POPULARITY_SORT_CRITERIA))
        {
            throw new ValidationException("Invalid sort criteria for this action.");
        }
    }
View Full Code Here

    @Override
    public void validate(final ActionContext inActionContext) throws ValidationException
    {
        if (((RenameTabRequest) inActionContext.getParams()).getTabName().length() > TabTemplate.MAX_TAB_NAME_LENGTH)
        {
            throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE);
        }
    }
View Full Code Here

        // TODO: refactor to get better validation.
        Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams();

        if (fields == null)
        {
            throw new ValidationException("UpdateSystemSettings requires Map of form data");
        }

        ValidationException ve = new ValidationException();

        if (fields.containsKey("ldapGroups") && ((List<MembershipCriteria>) fields.get("ldapGroups")).size() == 0)
        {
            ve.addError("ldapGroups", "At least one entry is required in the access list");
        }

        if (fields.containsKey("contentWarningText") && fields.get("contentWarningText") == null)
        {
            ve.addError("contentWarningText", CONTENT_WARNING_REQUIRED_ERROR_MESSAGE);
        }
        else if (fields.containsKey("contentWarningText")
                && ((String) fields.get("contentWarningText")).length() > SystemSettings.MAX_INPUT)
        {
            ve.addError("contentWarningText", CONTENT_WARNING_LENGTH_ERROR_MESSAGE);
        }

        if (fields.containsKey("siteLabel") && fields.get("siteLabel") == null)
        {
            ve.addError("siteLabel", SITE_LABEL_REQUIRED_ERROR_MESSAGE);
        }
        else if (fields.containsKey("siteLabel")
                && ((String) fields.get("siteLabel")).length() > SystemSettings.MAX_SITELABEL_INPUT)
        {
            ve.addError("siteLabel", SITE_LABEL_LENGTH_ERROR_MESSAGE);
        }

        if (fields.containsKey("termsOfService") && fields.get("termsOfService") == null)
        {
            ve.addError("termsOfService", TOS_REQUIRED_ERROR_MESSAGE);
        }

        if (fields.containsKey("pluginWarning") && fields.get("pluginWarning") == null)
        {
            ve.addError("pluginWarning", PLUGIN_WARNING_REQUIRED_ERROR_MESSAGE);
        }

        if (fields.containsKey("contentExpiration") && fields.get("contentExpiration") == null)
        {
            ve.addError("contentExpiration", CONTENT_EXPIRATION_REQUIRED_ERROR_MESSAGE);
        }
        else if (fields.containsKey("contentExpiration") && !(fields.get("contentExpiration") instanceof Integer))
        {
            ve.addError("contentExpiration", CONTENT_EXPIRATION_ERROR_MESSAGE);
        }
        else if (fields.containsKey("contentExpiration") && fields.get("contentExpiration") != null
                && fields.get("contentExpiration") instanceof Integer
                && ((Integer) fields.get("contentExpiration") < SystemSettings.MIN_CONTENT_EXPIRATION //
                || (Integer) fields.get("contentExpiration") > SystemSettings.MAX_CONTENT_EXPIRATION))
        {
            ve.addError("contentExpiration", CONTENT_EXPIRATION_ERROR_MESSAGE);
        }

        if (fields.containsKey("tosPromptInterval") && !(fields.get("tosPromptInterval") instanceof Integer))
        {
            ve.addError("tosPromptInterval", TOS_PROMPT_INTERVAL_INVALID_ERROR_MESSAGE);
        }
        else if (fields.containsKey("tosPromptInterval")
                && (Integer) fields.get("tosPromptInterval") < SystemSettings.MIN_TOS_PROMPT_INTERVAL)
        {
            ve.addError("tosPromptInterval", MIN_TOS_PROMPT_INTERVAL_ERROR_MESSAGE);
        }

        if (!fields.containsKey("admins") || fields.get("admins") == null
                || ((HashSet<Person>) fields.get("admins")).size() == 0)
        {
            ve.addError("admins", SYSTEM_ADMINISTRATORS_EMPTY_ERROR_MESSAGE);
        }
        else
        {
            boolean adminErrorOccurred = false;
            // see if the people exist
            HashSet<Person> requestedAdmins = (HashSet<Person>) fields.get("admins");
            List<Long> adminIds = new ArrayList<Long>();

            // convert the list of people to people ids
            for (Person person : requestedAdmins)
            {
                adminIds.add(person.getId());
            }
            // get the people from db/cache
            List<PersonModelView> foundPeople = peopleByIdsMapper.execute(adminIds);

            // check for locked users
            String lockedUsers = "";
            for (PersonModelView foundPerson : foundPeople)
            {
                if (foundPerson.isAccountLocked())
                {
                    if (lockedUsers.length() > 0)
                    {
                        lockedUsers += ", ";
                    }
                    lockedUsers += foundPerson.getAccountId();
                }
            }
            if (lockedUsers.length() > 0)
            {
                // some of the users are locked users
                ve.addError("admins", SYSTEM_ADMINISTRATOR_LOCKED_OUT_ERROR_MESSAGE + lockedUsers);
                adminErrorOccurred = true;
            }

            if (!adminErrorOccurred)
            {
                // check for missing users
                String missingUsers = "";
                for (Person requestedAdmin : requestedAdmins)
                {
                    if (!isPersonIdInPersonList(foundPeople, requestedAdmin.getId()))
                    {
                        // missing person
                        if (missingUsers.length() > 0)
                        {
                            missingUsers += ", ";
                        }
                        missingUsers += requestedAdmin.getAccountId();
                    }
                }
                if (missingUsers.length() > 0)
                {
                    // some of the users weren't found
                    ve.addError("admins", SYSTEM_ADMINISTRATOR_NOTFOUND_ERROR_MESSAGE + missingUsers);
                }
            }
        }

        if (!ve.getErrors().isEmpty())
        {
            throw ve;
        }
    }
View Full Code Here

        // GalleryItem is a URL, find or create.
        T inUseGalleryItem = galleryItemMapper.findByUrl(galleryItemUrl);
        if (inUseGalleryItem != null && inUseGalleryItem.getShowInGallery())
        {
            ValidationException ve = new ValidationException();
            ve.addError(URL_KEY, "Url has already been uploaded to Eureka");
            throw ve;
        }
        else if (inUseGalleryItem != null && !inUseGalleryItem.getShowInGallery())
        {
            outGalleryItem = inUseGalleryItem;
View Full Code Here

        DefaultTransactionDefinition transDef = new DefaultTransactionDefinition();
        transDef.setName("LookupActivityTransaction");
        transDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus transStatus = transMgr.getTransaction(transDef);

        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 be included for Share verbs.");
            throw ve;
        }

        List<Long> activityIds = new ArrayList<Long>(1);
        activityIds.add(new Long(inActivity.getBaseObjectProperties().get("originalActivityId")));
        inActivity.getBaseObjectProperties().remove("originalActivityId");
        List<ActivityDTO> originalActivityResults;
        try
        {
            originalActivityResults = activityMapper.execute(activityIds);

            // If the original activity cannot be found throw an error right away.
            if (originalActivityResults.size() == 0)
            {
                ve.addError("OriginalActivity", "activity being shared could not be found in the db.");
                throw ve;
            }

            // if a unuqie activity is not found throw an error.
            if (originalActivityResults.size() > 1)
            {
                ve.addError("OriginalActivity", "more than one result was found for the original activity id.");
            }

            ActivityDTO origActivity = originalActivityResults.get(0);

            if (origActivity.getDestinationStream().getType() == EntityType.GROUP)
            {
                DomainGroupModelView group = groupShortNameCacheMapper.fetchUniqueResult(origActivity
                        .getDestinationStream().getUniqueIdentifier());

                if (group != null && !group.isPublic())
                {
                    ve.addError("OriginalActivity", "OriginalActivity from a private group and can not be shared.");
                    throw ve;
                }
                else if (group == null)
                {
                    ve.addError("OriginalActivity", "OriginalActivity Group Entity not found.");
                }
            }

            if (!inActivity.getBaseObjectProperties().equals(origActivity.getBaseObjectProperties()))
            {
                ve.addError("BaseObjectProperties",
                        "Oringal Activity BaseObjectProperties must equal the properties of the Shared Activity.");
            }
            else
            {
                // Push the property back onto the object properties for use
                // in storing the original id.
                inActivity.getBaseObjectProperties().put("originalActivityId", activityIds.get(0).toString());
            }

            if (!inActivity.getOriginalActor().getUniqueIdentifier().equals(
                    origActivity.getActor().getUniqueIdentifier()))
            {
                ve.addError("OriginalActor",
                        "Original actor of the shared activity does not match the actor of the original activity.");
            }

            if (!inActivity.getBaseObjectType().equals(origActivity.getBaseObjectType()))
            {
                ve.addError("BaseObjectType", "activity must be of the same type as the original activity.");
            }

            transMgr.commit(transStatus);
        }
        catch (Exception ex)
        {
            transMgr.rollback(transStatus);
            ve.addError("OriginalActivity", "Error occurred accessing the original activity.");
        }

        if (!ve.getErrors().isEmpty())
        {
            throw ve;
        }
    }
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.