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");
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations