use of fi.otavanopisto.pyramus.domainmodel.base.SchoolField in project pyramus by otavanopisto.
the class SchoolRESTService method createSchool.
@Path("/schools")
@POST
@RESTPermit(SchoolPermissions.CREATE_SCHOOL)
public Response createSchool(fi.otavanopisto.pyramus.rest.model.School entity) {
if (entity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
if (entity.getFieldId() == null) {
return Response.status(Status.BAD_REQUEST).build();
}
String code = entity.getCode();
String name = entity.getName();
if (StringUtils.isBlank(code) || StringUtils.isBlank(name)) {
return Response.status(Status.BAD_REQUEST).build();
}
SchoolField schoolField = schoolController.findSchoolFieldById(entity.getFieldId());
if (schoolField == null) {
return Response.status(Status.BAD_REQUEST).build();
}
BillingDetails billingDetails = null;
School school = schoolController.createSchool(code, name, schoolField, billingDetails);
if (entity.getTags() != null) {
schoolController.updateSchoolTags(school, entity.getTags());
}
if (entity.getVariables() != null) {
Set<String> variableKeys = entity.getVariables().keySet();
for (String variableKey : variableKeys) {
SchoolVariableKey schoolVariableKey = schoolController.findSchoolVariableKeyByVariableKey(variableKey);
if (schoolVariableKey == null) {
return Response.status(Status.BAD_REQUEST).build();
}
schoolController.createSchoolVariable(school, schoolVariableKey, entity.getVariables().get(variableKey));
}
}
schoolController.updateSchoolAdditionalContactInfo(school, entity.getAdditionalContactInfo());
return Response.ok(objectFactory.createModel(school)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.SchoolField in project pyramus by otavanopisto.
the class SchoolRESTService method updateSchoolField.
@Path("/schoolFields/{ID:[0-9]*}")
@PUT
@RESTPermit(SchoolPermissions.UPDATE_SCHOOLFIELD)
public Response updateSchoolField(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.SchoolField entity) {
if (entity == null) {
return Response.status(Status.BAD_REQUEST).build();
}
SchoolField schoolField = schoolController.findSchoolFieldById(id);
if (schoolField == null) {
return Response.status(Status.NOT_FOUND).build();
}
String name = entity.getName();
if (StringUtils.isBlank(name)) {
return Response.status(Status.BAD_REQUEST).build();
}
return Response.ok(objectFactory.createModel(schoolController.updateSchoolField(schoolField, name))).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.SchoolField in project pyramus by otavanopisto.
the class CreateSchoolJSONRequestController method process.
/**
* Processes the request to create a new grading scale.
*
* @param requestContext The JSON request context
*/
public void process(JSONRequestContext requestContext) {
SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
BillingDetailsDAO billingDetailsDAO = DAOFactory.getInstance().getBillingDetailsDAO();
String schoolCode = requestContext.getString("code");
String schoolName = requestContext.getString("name");
String tagsText = requestContext.getString("tags");
Long schoolFieldId = requestContext.getLong("schoolFieldId");
SchoolField schoolField = null;
if (schoolFieldId != null && schoolFieldId.intValue() >= 0)
schoolField = schoolFieldDAO.findById(schoolFieldId);
Set<Tag> tagEntities = new HashSet<>();
if (!StringUtils.isBlank(tagsText)) {
List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
for (String tag : tags) {
if (!StringUtils.isBlank(tag)) {
Tag tagEntity = tagDAO.findByText(tag.trim());
if (tagEntity == null)
tagEntity = tagDAO.create(tag);
tagEntities.add(tagEntity);
}
}
}
String billingPersonName = requestContext.getString("billingDetailsPersonName");
String billingCompanyName = requestContext.getString("billingDetailsCompanyName");
String billingStreetAddress1 = requestContext.getString("billingDetailsStreetAddress1");
String billingStreetAddress2 = requestContext.getString("billingDetailsStreetAddress2");
String billingPostalCode = requestContext.getString("billingDetailsPostalCode");
String billingCity = requestContext.getString("billingDetailsCity");
String billingRegion = requestContext.getString("billingDetailsRegion");
String billingCountry = requestContext.getString("billingDetailsCountry");
String billingPhoneNumber = requestContext.getString("billingDetailsPhoneNumber");
String billingEmailAddress = requestContext.getString("billingDetailsEmailAddress");
String billingElectronicBillingAddress = requestContext.getString("billingDetailsElectronicBillingAddress");
String billingElectronicBillingOperator = requestContext.getString("billingDetailsElectronicBillingOperator");
String billingCompanyIdentifier = requestContext.getString("billingDetailsCompanyIdentifier");
String billingReferenceNumber = requestContext.getString("billingDetailsReferenceNumber");
String billingNotes = requestContext.getString("billingDetailsNotes");
BillingDetails billingDetails = billingDetailsDAO.create(billingPersonName, billingCompanyName, billingStreetAddress1, billingStreetAddress2, billingPostalCode, billingCity, billingRegion, billingCountry, billingPhoneNumber, billingEmailAddress, billingElectronicBillingAddress, billingElectronicBillingOperator, billingCompanyIdentifier, billingReferenceNumber, billingNotes);
School school = schoolDAO.create(schoolCode, schoolName, schoolField, billingDetails);
// Tags
schoolDAO.updateTags(school, tagEntities);
// Addresses
int addressCount = requestContext.getInteger("addressTable.rowCount");
for (int i = 0; i < addressCount; i++) {
String colPrefix = "addressTable." + i;
Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
String name = requestContext.getString(colPrefix + ".name");
String street = requestContext.getString(colPrefix + ".street");
String postal = requestContext.getString(colPrefix + ".postal");
String city = requestContext.getString(colPrefix + ".city");
String country = requestContext.getString(colPrefix + ".country");
boolean hasAddress = name != null || street != null || postal != null || city != null || country != null;
if (hasAddress) {
addressDAO.create(school.getContactInfo(), contactType, name, street, postal, city, country, defaultAddress);
}
}
// Email addresses
int emailCount = requestContext.getInteger("emailTable.rowCount");
for (int i = 0; i < emailCount; i++) {
String colPrefix = "emailTable." + i;
Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
String email = requestContext.getString(colPrefix + ".email");
// Trim the email address
email = email != null ? email.trim() : null;
if (email != null) {
emailDAO.create(school.getContactInfo(), contactType, defaultAddress, email);
}
}
// Phone numbers
int phoneCount = requestContext.getInteger("phoneTable.rowCount");
for (int i = 0; i < phoneCount; i++) {
String colPrefix = "phoneTable." + i;
Boolean defaultNumber = requestContext.getBoolean(colPrefix + ".defaultNumber");
ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
String number = requestContext.getString(colPrefix + ".phone");
if (number != null) {
phoneNumberDAO.create(school.getContactInfo(), contactType, defaultNumber, number);
}
}
// Variables
Integer variableCount = requestContext.getInteger("variablesTable.rowCount");
if (variableCount != null) {
for (int i = 0; i < variableCount; i++) {
String colPrefix = "variablesTable." + i;
String key = requestContext.getRequest().getParameter(colPrefix + ".key");
String value = requestContext.getRequest().getParameter(colPrefix + ".value");
schoolVariableDAO.setVariable(school, key, value);
}
}
String redirectURL = requestContext.getRequest().getContextPath() + "/settings/editschool.page?school=" + school.getId();
String refererAnchor = requestContext.getRefererAnchor();
if (!StringUtils.isBlank(refererAnchor))
redirectURL += "#" + refererAnchor;
requestContext.setRedirectURL(redirectURL);
}
use of fi.otavanopisto.pyramus.domainmodel.base.SchoolField in project pyramus by otavanopisto.
the class ArchiveSchoolFieldJSONRequestController method process.
public void process(JSONRequestContext requestContext) {
SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
Long schoolFieldId = NumberUtils.createLong(requestContext.getRequest().getParameter("schoolFieldId"));
SchoolField schoolField = schoolFieldDAO.findById(schoolFieldId);
schoolFieldDAO.archive(schoolField);
}
use of fi.otavanopisto.pyramus.domainmodel.base.SchoolField in project pyramus by otavanopisto.
the class SchoolAPI method create.
public Long create(String code, String name, Long schoolField) {
SchoolField schoolFieldEntity = null;
BillingDetails billingDetails = null;
if (schoolField != null) {
schoolFieldEntity = DAOFactory.getInstance().getSchoolFieldDAO().findById(schoolField);
}
return (DAOFactory.getInstance().getSchoolDAO().create(code, name, schoolFieldEntity, billingDetails).getId());
}
Aggregations