Search in sources :

Example 1 with InvalidQueryException

use of io.hops.hopsworks.exceptions.InvalidQueryException in project hopsworks by logicalclocks.

the class AbstractFacade method getDate.

public Date getDate(String field, String value) {
    String[] formats = { "yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ssX", "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:sss", "yyyy-MM-dd" };
    Date date = null;
    for (int i = 0; i < formats.length && date == null; i++) {
        date = getDateByFormat(value, formats[i]);
    }
    if (date == null) {
        throw new InvalidQueryException("Filter value for " + field + " needs to set valid format. Expected:yyyy-MM-dd hh:mm:ss.SSSX but found: " + value);
    }
    return date;
}
Also used : Date(java.util.Date) InvalidQueryException(io.hops.hopsworks.exceptions.InvalidQueryException)

Example 2 with InvalidQueryException

use of io.hops.hopsworks.exceptions.InvalidQueryException in project hopsworks by logicalclocks.

the class UserFacade method getTypeValue.

private UserAccountType getTypeValue(String field, String value) {
    if (value == null || value.isEmpty()) {
        throw new InvalidQueryException("Filter value for " + field + " needs to set an Integer or a valid " + field + ", but found: " + value);
    }
    UserAccountType val;
    try {
        int v = Integer.parseInt(value);
        val = UserAccountType.fromValue(v);
    } catch (IllegalArgumentException e) {
        try {
            val = UserAccountType.valueOf(value);
        } catch (IllegalArgumentException ie) {
            throw new InvalidQueryException("Filter value for " + field + " needs to set an Integer or a valid " + field + ", but found: " + value);
        }
    }
    return val;
}
Also used : InvalidQueryException(io.hops.hopsworks.exceptions.InvalidQueryException) UserAccountType(io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountType)

Example 3 with InvalidQueryException

use of io.hops.hopsworks.exceptions.InvalidQueryException in project hopsworks by logicalclocks.

the class JobFacade method getJobStates.

private Set<JobState> getJobStates(String field, String values) {
    String[] jobStatesArr = values.split(",");
    Set<JobState> jobStates = new HashSet<>();
    for (String jobState : jobStatesArr) {
        try {
            jobStates.add(JobState.valueOf(jobState.trim().toUpperCase()));
        } catch (IllegalArgumentException ie) {
            throw new InvalidQueryException("Filter value for " + field + " needs to set a valid " + field + ", but found: " + jobState);
        }
    }
    if (jobStates.isEmpty()) {
        throw new InvalidQueryException("Filter value for " + field + " needs to set valid job state, but found: " + values);
    }
    return jobStates;
}
Also used : JobState(io.hops.hopsworks.persistence.entity.jobs.configuration.history.JobState) InvalidQueryException(io.hops.hopsworks.exceptions.InvalidQueryException) HashSet(java.util.HashSet)

Example 4 with InvalidQueryException

use of io.hops.hopsworks.exceptions.InvalidQueryException in project hopsworks by logicalclocks.

the class JobFacade method getJobTypes.

public static Set<JobType> getJobTypes(String field, String values) {
    String[] jobTypesArr = values.split(",");
    Set<JobType> jobTypes = new HashSet<>();
    for (String jobType : jobTypesArr) {
        try {
            jobTypes.add(JobType.valueOf(jobType.trim().toUpperCase()));
        } catch (IllegalArgumentException ie) {
            throw new InvalidQueryException("Filter value for " + field + " needs to set a valid " + field + ", but found: " + jobType);
        }
    }
    if (jobTypes.isEmpty()) {
        throw new InvalidQueryException("Filter value for " + field + " needs to set valid job types, but found: " + values);
    }
    return jobTypes;
}
Also used : JobType(io.hops.hopsworks.persistence.entity.jobs.configuration.JobType) InvalidQueryException(io.hops.hopsworks.exceptions.InvalidQueryException) HashSet(java.util.HashSet)

Example 5 with InvalidQueryException

use of io.hops.hopsworks.exceptions.InvalidQueryException in project hopsworks by logicalclocks.

the class UserFacade method getStatusValue.

private UserAccountStatus getStatusValue(String field, String value) {
    if (value == null || value.isEmpty()) {
        throw new InvalidQueryException("Filter value for " + field + " needs to set an Integer or a valid " + field + ", but found: " + value);
    }
    UserAccountStatus val;
    try {
        int v = Integer.parseInt(value);
        val = UserAccountStatus.fromValue(v);
    } catch (IllegalArgumentException e) {
        try {
            val = UserAccountStatus.valueOf(value);
        } catch (IllegalArgumentException ie) {
            throw new InvalidQueryException("Filter value for " + field + " needs to set an Integer or a valid " + field + ", but found: " + value);
        }
    }
    return val;
}
Also used : UserAccountStatus(io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountStatus) InvalidQueryException(io.hops.hopsworks.exceptions.InvalidQueryException)

Aggregations

InvalidQueryException (io.hops.hopsworks.exceptions.InvalidQueryException)6 HashSet (java.util.HashSet)2 JobType (io.hops.hopsworks.persistence.entity.jobs.configuration.JobType)1 JobState (io.hops.hopsworks.persistence.entity.jobs.configuration.history.JobState)1 BbcGroup (io.hops.hopsworks.persistence.entity.user.BbcGroup)1 UserAccountStatus (io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountStatus)1 UserAccountType (io.hops.hopsworks.persistence.entity.user.security.ua.UserAccountType)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1