Package org.eurekastreams.commons.exceptions

Examples of org.eurekastreams.commons.exceptions.ValidationException


    @Override
    public void validate(final PrincipalActionContext inActionContext) throws ValidationException
    {
        Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams();

        ValidationException ve = new ValidationException();
        ValidationHelper vHelper = new ValidationHelper();

        vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.ID_KEY, true, ve);
        vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.SHORT_NAME_KEY, true, ve);

        String url = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.URL_KEY, false, ve);
        vHelper.stringMeetsRequirments(DomainGroupModelView.URL_KEY, url, ve, null, null, null,
                CompositeEntity.URL_REGEX_PATTERN, DomainGroup.WEBSITE_MESSAGE);

        if (fields.containsKey(DomainGroupModelView.PRIVACY_KEY))
        {
            throw new ValidationException(ValidationHelper.UNEXPECTED_DATA_ERROR_MESSAGE);
        }

        Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY,
                true, ve);
        if (coordinators == null || coordinators.isEmpty())
        {
            ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE);
        }

        String name = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve);
        if (name == null || name.isEmpty())
        {
            ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED);
        }
        else
        {
            vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, name, ve, DomainGroup.NAME_LENGTH_MESSAGE,
                    DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.GROUP_NAME_PATTERN,
                    DomainGroup.GROUP_NAME_MESSAGE);
        }

        String description = (String) vHelper.getAndCheckStringFieldExist(fields,
                DomainGroupModelView.DESCRIPTION_KEY, true, ve);
        vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, description, ve, null,
                DomainGroup.MAX_DESCRIPTION_LENGTH, DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null);

        String keywords = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.KEYWORDS_KEY,
                true, ve);

        if (keywords != null)
        {
            if (!vHelper.validBackgroundItems(keywords))
            {
                ve.addError(DomainGroupModelView.KEYWORDS_KEY, DomainGroupModelView.KEYWORD_MESSAGE);
            }
        }

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


    public void validate(final ActionContext inActionContext) throws ValidationException
    {
        String category = (String) inActionContext.getParams();
        if (!categories.contains(category))
        {
            throw new ValidationException("Invalid notification category: " + category);
        }
    }
View Full Code Here

    {
        Long videoID = (Long) inActionContext.getParams();

        if (optOutVideoMapper.execute(new FindByIdRequest("TutorialVideo", videoID)) == null)
        {
            throw (new ValidationException("Not a valid video id"));
        }
    }
View Full Code Here

     */
    @Override
    public void validate(final ActionContext inActionContext) throws ValidationException
    {
        SendPrebuiltNotificationRequest params = (SendPrebuiltNotificationRequest) inActionContext.getParams();
        ValidationException ve = new ValidationException();

        // message
        if (params.getMessage() == null || params.getMessage().isEmpty())
        {
            ve.addError("message", "Message must be provided.");
        }
        else if (params.getMessage().length() > maxMessageLength)
        {
            ve.addError("message", "Message must be no more than " + maxMessageLength + " characters.");
        }
        // TODO: Should we check content of message?

        // URL
        if (params.getUrl() != null && params.getUrl().length() > maxUrlLength)
        {
            ve.addError("url", "URL must be no more than " + maxUrlLength + " characters.");
        }
        // TODO: Should we check format of URL?

        if (ve.hasErrors())
        {
            throw ve;
        }
    }
View Full Code Here

        // verify description length.
        String description = dto.getDescription();
        if (StringUtils.isEmpty(description) || (description.length() > maxLength))
        {
            throw new ValidationException("Description must be present and less than " + maxLength + " characters");
        }

        // verify streamscope not null and is correct type.
        StreamScope streamScope = streamScopeMapper.execute(new FindByIdRequest("StreamScope", dto.getStreamId()));
        if (streamScope == null)
        {
            throw new ValidationException("Stream not found");
        }

        // put in state so action doesn't need to look it up again or use placeholder object.
        inActionContext.getState().put("streamScope", streamScope);

        // verify that featured stream belongs to person or group.
        if (streamScope.getScopeType() != ScopeType.PERSON && streamScope.getScopeType() != ScopeType.GROUP)
        {
            throw new ValidationException("Only person and group streams supported.");
        }

    }
View Full Code Here

    @Override
    public void validate(final ActionContext inActionContext) throws ValidationException
    {
        Map<String, Serializable> fields = (Map<String, Serializable>) inActionContext.getParams();

        ValidationException ve = new ValidationException();
        ValidationHelper vHelper = new ValidationHelper();

        String groupName = (String) vHelper
                .getAndCheckStringFieldExist(fields, DomainGroupModelView.NAME_KEY, true, ve);
        if (groupName == null || groupName.isEmpty())
        {
            ve.addError(DomainGroupModelView.NAME_KEY, DomainGroup.NAME_REQUIRED);
        }
        else
        {
            vHelper.stringMeetsRequirments(DomainGroupModelView.NAME_KEY, groupName, ve,
                    DomainGroup.NAME_LENGTH_MESSAGE, DomainGroup.MAX_NAME_LENGTH, DomainGroup.NAME_LENGTH_MESSAGE,
                    DomainGroup.GROUP_NAME_PATTERN, DomainGroup.GROUP_NAME_MESSAGE);
        }

        String groupShortName = (String) vHelper.getAndCheckStringFieldExist(fields,
                DomainGroupModelView.SHORT_NAME_KEY, true, ve);
        if (groupShortName == null || groupShortName.isEmpty())
        {
            ve.addError(DomainGroupModelView.SHORT_NAME_KEY, DomainGroup.SHORTNAME_REQUIRED);
        }
        else if (vHelper.stringMeetsRequirments(DomainGroupModelView.SHORT_NAME_KEY, groupShortName, ve,
                DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.MAX_SHORT_NAME_LENGTH,
                DomainGroup.SHORT_NAME_LENGTH_MESSAGE, DomainGroup.ALPHA_NUMERIC_PATTERN,
                DomainGroup.SHORT_NAME_CHARACTERS))
        {
            // TODO This is a less than ideal fix due to time constraints for the 1.5 release.
            // Recommend removing try/catch and evaluating why group creation is broken
            try
            {
                if (groupMapper.findByShortName(groupShortName.toLowerCase()) != null)
                {
                    ve.addError(DomainGroupModelView.SHORT_NAME_KEY, SHORTNAME_TAKEN_MESSAGE);
                }
            }
            catch (Exception ex)
            {
                int x = 0;
            }
        }

        String groupDesc = (String) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.DESCRIPTION_KEY,
                true, ve);
        if (groupDesc == null || groupDesc.isEmpty())
        {
            ve.addError(DomainGroupModelView.DESCRIPTION_KEY, DomainGroup.DESCRIPTION_REQUIRED);
        }
        else
        {
            vHelper.stringMeetsRequirments(DomainGroupModelView.DESCRIPTION_KEY, groupDesc, ve,
                    DomainGroup.DESCRIPTION_LENGTH_MESSAGE, DomainGroup.MAX_DESCRIPTION_LENGTH,
                    DomainGroup.DESCRIPTION_LENGTH_MESSAGE, null, null);
        }

        Set coordinators = (Set) vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.COORDINATORS_KEY,
                true, ve);
        if (coordinators == null || coordinators.isEmpty())
        {
            ve.addError(DomainGroupModelView.COORDINATORS_KEY, DomainGroup.MIN_COORDINATORS_MESSAGE);
        }

        vHelper.getAndCheckStringFieldExist(fields, DomainGroupModelView.PRIVACY_KEY, true, ve);

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

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

        ValidationException vex = new ValidationException();

        if (!inRequest.getTargetEntityType().equals(EntityType.PERSON))
        {
            vex.addError("EntityType", "This action only supports following a person.");
        }

        Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId());

        if (followingId == null)
        {
            vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied.");
        }

        if (vex.getErrors().size() > 0)
        {
            throw vex;
        }
    }
View Full Code Here

        // TODO #performance make customized request to get tab count instead of pulling back whole object.
        Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId()));

        if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT)
        {
            throw new ValidationException(Person.TAB_LIMIT_MESSAGE);
        }

        if (validateTabName)
        {
            if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH)
            {
                throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE);
            }
        }

    }
View Full Code Here

     * {@inheritDoc}.
     */
    @Override
    public void validate(final ServiceActionContext inActionContext)
    {
        ValidationException valEx = new ValidationException();

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

        ActivityDTO currentActivity = currentRequest.getActivityDTO();

        // All activities must have a destination stream.
        if (currentActivity.getDestinationStream() == null
                || currentActivity.getDestinationStream().getUniqueIdentifier() == null
                || currentActivity.getDestinationStream().getUniqueIdentifier().length() <= 0)
        {
            valEx.addError("destination_stream", "Activities require a Destination Stream.");
            throw valEx;
        }

        // All activities must be posted to either a person or group stream.
        if (!((currentActivity.getDestinationStream().getType() == EntityType.PERSON)
                || (currentActivity.getDestinationStream().getType() == EntityType.GROUP) || currentActivity
                .getDestinationStream().getType() == EntityType.RESOURCE))
        {
            valEx.addError("destination_stream_type",
                    "Activities can only be submitted to Person, Group, or Resource streams.");
            throw valEx;
        }

        // If there are verb and object validator instances available use them
        // to validate the
        // activity object, if not, throw an exception.
        if (verbValidators.containsKey(currentActivity.getVerb().name())
                && objectValidators.containsKey(currentActivity.getBaseObjectType().name()))
        {
            try
            {
                ActivityValidator currentVerbVal = verbValidators.get(currentActivity.getVerb().name());
                currentVerbVal.validate(currentActivity);

                ActivityValidator currentObjectVal = objectValidators.get(currentActivity.getBaseObjectType().name());
                currentObjectVal.validate(currentActivity);
            }
            catch (ValidationException vex)
            {
                log.error("ActivityValidators failed for this activity.", vex);
                for (Entry<String, String> validationError : vex.getErrors().entrySet())
                {
                    valEx.addError(validationError.getKey(), validationError.getValue());
                    log.error("Error key: " + validationError.getKey() + " message: " + validationError.getValue());
                }
                throw valEx;
            }
        }
        else
        {
            valEx.addError("validator_required",
                    "The supplied activity does not have a corresponding validator and cannot be persisted.");
            throw valEx;
        }
    }
View Full Code Here

     */
    @Override
    public void validate(final ClientPrincipalActionContext inActionContext) throws ValidationException
    {
        SendPrebuiltNotificationRequest params = (SendPrebuiltNotificationRequest) inActionContext.getParams();
        ValidationException ve = new ValidationException();

        // insure valid recipient
        PersonModelView recipient = personMapper.execute(params.getRecipientAccountId());
        if (recipient == null)
        {
            ve.addError("recipientAccountId", "Unknown or missing recipient account id.");
        }
        else if (recipient.isAccountLocked())
        {
            ve.addError("recipientAccountId", "Cannot send notifications to locked users.");
        }
        else
        {
            inActionContext.getState().put("recipient", recipient);
        }

        // message
        if (params.getMessage() == null || params.getMessage().isEmpty())
        {
            ve.addError("message", "Message must be provided.");
        }
        else if (params.getMessage().length() > maxMessageLength)
        {
            ve.addError("message", "Message must be no more than " + maxMessageLength + " characters.");
        }
        // TODO: Should we check content of message?

        // URL
        if (params.getUrl() != null && params.getUrl().length() > maxUrlLength)
        {
            ve.addError("url", "URL must be no more than " + maxUrlLength + " characters.");
        }
        // TODO: Should we check format of URL?

        if (ve.hasErrors())
        {
            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.