Search in sources :

Example 1 with CourseBaseVariableKey

use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey in project pyramus by otavanopisto.

the class CourseBaseVariableDAO method findByCourseAndVariableKey.

public String findByCourseAndVariableKey(Course course, String key) {
    CourseBaseVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
    CourseBaseVariableKey courseBaseVariableKey = variableKeyDAO.findByVariableKey(key);
    if (courseBaseVariableKey != null) {
        CourseBaseVariable courseBaseVariable = findByCourseAndVariableKey(course, courseBaseVariableKey);
        return courseBaseVariable == null ? null : courseBaseVariable.getValue();
    } else {
        throw new PersistenceException("Unknown VariableKey");
    }
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) PersistenceException(javax.persistence.PersistenceException)

Example 2 with CourseBaseVariableKey

use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey in project pyramus by otavanopisto.

the class CourseBaseVariableKeyDAO method create.

public CourseBaseVariableKey create(String variableKey, String variableName, VariableType variableType, Boolean userEditable) {
    CourseBaseVariableKey courseBaseVariableKey = new CourseBaseVariableKey();
    courseBaseVariableKey.setUserEditable(userEditable);
    courseBaseVariableKey.setVariableKey(variableKey);
    courseBaseVariableKey.setVariableName(variableName);
    courseBaseVariableKey.setVariableType(variableType);
    return persist(courseBaseVariableKey);
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey)

Example 3 with CourseBaseVariableKey

use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey in project pyramus by otavanopisto.

the class ModuleRESTService method createVariable.

@Path("/variables")
@POST
@RESTPermit(CommonPermissions.CREATE_COURSEBASEVARIABLEKEY)
public Response createVariable(fi.otavanopisto.pyramus.rest.model.VariableKey entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (StringUtils.isBlank(entity.getKey()) || StringUtils.isBlank(entity.getName()) || entity.getType() == null || entity.getUserEditable() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    VariableType variableType = null;
    switch(entity.getType()) {
        case BOOLEAN:
            variableType = VariableType.BOOLEAN;
            break;
        case DATE:
            variableType = VariableType.DATE;
            break;
        case NUMBER:
            variableType = VariableType.NUMBER;
            break;
        case TEXT:
            variableType = VariableType.TEXT;
            break;
    }
    CourseBaseVariableKey courseBaseVariableKey = commonController.createCourseBaseVariableKey(entity.getKey(), entity.getName(), variableType, entity.getUserEditable());
    return Response.ok(objectFactory.createModel(courseBaseVariableKey)).build();
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) VariableType(fi.otavanopisto.pyramus.domainmodel.base.VariableType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) POST(javax.ws.rs.POST)

Example 4 with CourseBaseVariableKey

use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey in project pyramus by otavanopisto.

the class ModuleRESTService method deleteVariable.

@Path("/variables/{KEY}")
@DELETE
@RESTPermit(CommonPermissions.DELETE_COURSEBASEVARIABLEKEY)
public Response deleteVariable(@PathParam("KEY") String key) {
    CourseBaseVariableKey courseBaseVariableKey = commonController.findCourseBaseVariableKeyByVariableKey(key);
    if (courseBaseVariableKey == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    commonController.deleteCourseBaseVariableKey(courseBaseVariableKey);
    return Response.noContent().build();
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Example 5 with CourseBaseVariableKey

use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey in project pyramus by otavanopisto.

the class CourseRESTService method updateVariable.

@Path("/variables/{KEY}")
@PUT
@RESTPermit(CommonPermissions.UPDATE_COURSEBASEVARIABLEKEY)
public Response updateVariable(@PathParam("KEY") String key, fi.otavanopisto.pyramus.rest.model.VariableKey entity) {
    if (entity == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (StringUtils.isBlank(entity.getName()) || entity.getType() == null || entity.getUserEditable() == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    CourseBaseVariableKey courseBaseVariableKey = commonController.findCourseBaseVariableKeyByVariableKey(key);
    if (courseBaseVariableKey == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    VariableType variableType = null;
    switch(entity.getType()) {
        case BOOLEAN:
            variableType = VariableType.BOOLEAN;
            break;
        case DATE:
            variableType = VariableType.DATE;
            break;
        case NUMBER:
            variableType = VariableType.NUMBER;
            break;
        case TEXT:
            variableType = VariableType.TEXT;
            break;
    }
    commonController.updateCourseBaseVariableKey(courseBaseVariableKey, entity.getName(), variableType, entity.getUserEditable());
    return Response.ok(objectFactory.createModel(courseBaseVariableKey)).build();
}
Also used : CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) VariableType(fi.otavanopisto.pyramus.domainmodel.base.VariableType) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Aggregations

CourseBaseVariableKey (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey)16 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)6 Path (javax.ws.rs.Path)6 CourseBaseVariable (fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable)5 VariableType (fi.otavanopisto.pyramus.domainmodel.base.VariableType)5 CourseBaseVariableKeyDAO (fi.otavanopisto.pyramus.dao.base.CourseBaseVariableKeyDAO)3 EntityManager (javax.persistence.EntityManager)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)2 HashSet (java.util.HashSet)2 DELETE (javax.ws.rs.DELETE)2 Address (fi.otavanopisto.pyramus.domainmodel.base.Address)1 BillingDetails (fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)1 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)1 ContactURL (fi.otavanopisto.pyramus.domainmodel.base.ContactURL)1 ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)1 CourseEducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype)1 CourseEducationType (fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType)1 EducationSubtype (fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype)1 EducationType (fi.otavanopisto.pyramus.domainmodel.base.EducationType)1