Search in sources :

Example 6 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class ArchiveEntryValidator method lookup.

public static ArchiveEntry lookup(ArchiveEntry archiveEntry, String name) throws InputValidationException {
    if (archiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isYearMonthLookup = false;
    if (archiveEntry.id != null) {
        isIdLookup = true;
    } else if (archiveEntry.year != null && archiveEntry.month != null) {
        isYearMonthLookup = true;
    }
    if (!(isIdLookup || isYearMonthLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    ArchiveEntry lookupArchiveEntry = null;
    if (isIdLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getArchiveEntry(archiveEntry.id);
    } else if (isYearMonthLookup) {
        lookupArchiveEntry = ArchiveEntryServiceProvider.provide().getMonthArchiveEntry(archiveEntry.month, archiveEntry.year);
    }
    if (lookupArchiveEntry == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupArchiveEntry;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) ArchiveEntry(com.willshex.blogwt.shared.api.datatype.ArchiveEntry)

Example 7 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class MetaNotificationValidator method lookup.

public static MetaNotification lookup(MetaNotification metaNotification, String name) throws InputValidationException {
    notNull(metaNotification, CLASS, name);
    boolean isIdLookup = false, isCodeLookup = false;
    if (metaNotification.id != null) {
        isIdLookup = true;
    } else if (metaNotification.code != null) {
        isCodeLookup = true;
    }
    if (!(isIdLookup || isCodeLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    MetaNotification lookupMetaNotification = null;
    if (isIdLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getMetaNotification(metaNotification.id);
    } else if (isCodeLookup) {
        lookupMetaNotification = MetaNotificationServiceProvider.provide().getCodeMetaNotification(metaNotification.code);
    }
    if (lookupMetaNotification == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupMetaNotification;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) MetaNotification(com.willshex.blogwt.shared.api.datatype.MetaNotification)

Example 8 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class NotificationSettingValidator method lookup.

public static NotificationSetting lookup(NotificationSetting notificationSetting, String name) throws InputValidationException {
    notNull(notificationSetting, CLASS, name);
    boolean isIdLookup = false, isUserMetaNotificationLookup = false;
    if (notificationSetting.id != null) {
        isIdLookup = true;
    } else if (notificationSetting.user != null && notificationSetting.meta != null) {
        isUserMetaNotificationLookup = true;
    }
    if (!(isIdLookup || isUserMetaNotificationLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    NotificationSetting lookupNotificationSetting = null;
    if (isIdLookup) {
        notificationSetting = NotificationSettingServiceProvider.provide().getNotificationSetting(notificationSetting.id);
    } else if (isUserMetaNotificationLookup) {
        notificationSetting.user = UserValidator.lookup(notificationSetting.user, name + ".user");
        notificationSetting.meta = MetaNotificationValidator.lookup(notificationSetting.meta, name + ".meta");
        notificationSetting = NotificationSettingServiceProvider.provide().getMetaUserNotificationSetting(notificationSetting.meta, notificationSetting.user);
    }
    if (lookupNotificationSetting == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return notificationSetting;
}
Also used : NotificationSetting(com.willshex.blogwt.shared.api.datatype.NotificationSetting) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 9 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class PageValidator method lookup.

public static Page lookup(Page page, String name) throws InputValidationException {
    if (page == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false, isSlugLookup = false;
    if (page.id != null) {
        isIdLookup = true;
    } else if (page.slug != null) {
        isSlugLookup = true;
    }
    if (!(isIdLookup || isSlugLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Page lookupPage;
    if (isIdLookup) {
        lookupPage = PageServiceProvider.provide().getPage(page.id);
    } else {
        lookupPage = PageServiceProvider.provide().getSlugPage(page.slug, Boolean.FALSE);
    }
    if (lookupPage == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupPage;
}
Also used : InputValidationException(com.willshex.gson.web.service.server.InputValidationException) Page(com.willshex.blogwt.shared.api.datatype.Page)

Example 10 with InputValidationException

use of com.willshex.gson.web.service.server.InputValidationException in project blogwt by billy1380.

the class ResourceValidator method lookup.

public static Resource lookup(Resource resource, String name) throws InputValidationException {
    if (resource == null)
        throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, TYPE + ": " + name);
    boolean isIdLookup = false;
    if (resource.id != null) {
        isIdLookup = true;
    }
    if (!isIdLookup)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    Resource lookupResource = null;
    if (isIdLookup) {
        lookupResource = ResourceServiceProvider.provide().getResource(resource.id);
    }
    if (lookupResource == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupResource;
}
Also used : Resource(com.willshex.blogwt.shared.api.datatype.Resource) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Aggregations

InputValidationException (com.willshex.gson.web.service.server.InputValidationException)25 User (com.willshex.blogwt.shared.api.datatype.User)9 Post (com.willshex.blogwt.shared.api.datatype.Post)5 Permission (com.willshex.blogwt.shared.api.datatype.Permission)3 Property (com.willshex.blogwt.shared.api.datatype.Property)3 Relationship (com.willshex.blogwt.shared.api.datatype.Relationship)3 Key (com.googlecode.objectify.Key)2 Page (com.willshex.blogwt.shared.api.datatype.Page)2 Role (com.willshex.blogwt.shared.api.datatype.Role)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AuthorisationException (com.willshex.blogwt.server.api.exception.AuthorisationException)1 ArchiveEntry (com.willshex.blogwt.shared.api.datatype.ArchiveEntry)1 GeneratedDownload (com.willshex.blogwt.shared.api.datatype.GeneratedDownload)1 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)1 NotificationSetting (com.willshex.blogwt.shared.api.datatype.NotificationSetting)1 Rating (com.willshex.blogwt.shared.api.datatype.Rating)1 Resource (com.willshex.blogwt.shared.api.datatype.Resource)1 Session (com.willshex.blogwt.shared.api.datatype.Session)1 Tag (com.willshex.blogwt.shared.api.datatype.Tag)1