Search in sources :

Example 1 with SchoolFieldDAO

use of fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO in project pyramus by otavanopisto.

the class EditSchoolViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
    SchoolVariableKeyDAO schoolVariableKeyDAO = DAOFactory.getInstance().getSchoolVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    Long schoolId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("school"));
    School school = schoolDAO.findById(schoolId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = school.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<SchoolVariableKey> schoolUserEditableVariableKeys = schoolVariableKeyDAO.listUserEditableVariableKeys();
    Collections.sort(schoolUserEditableVariableKeys, new StringAttributeComparator("getVariableName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("id", "name").extractString(contactTypes);
    List<Address> addresses = school.getContactInfo().getAddresses();
    JSONArray jsonAddresses = new JSONArrayExtractor("id", "defaultAddress", "name", "streetAddress", "postalCode", "city", "country").extract(addresses);
    for (int i = 0; i < jsonAddresses.size(); i++) {
        JSONObject jsonAddress = jsonAddresses.getJSONObject(i);
        if (addresses.get(i).getContactType() != null) {
            jsonAddress.put("contactTypeId", addresses.get(i).getContactType().getId());
        }
    }
    List<Email> emails = school.getContactInfo().getEmails();
    JSONArray jsonEmails = new JSONArrayExtractor("id", "defaultAddress", "address").extract(emails);
    for (int i = 0; i < jsonEmails.size(); i++) {
        JSONObject jsonEmail = jsonEmails.getJSONObject(i);
        if (emails.get(i).getContactType() != null) {
            jsonEmail.put("contactTypeId", emails.get(i).getContactType().getId());
        }
    }
    List<PhoneNumber> phoneNumbers = school.getContactInfo().getPhoneNumbers();
    JSONArray jsonPhoneNumbers = new JSONArrayExtractor("id", "defaultNumber", "number").extract(phoneNumbers);
    for (int i = 0; i < jsonPhoneNumbers.size(); i++) {
        JSONObject jsonPhoneNumber = jsonPhoneNumbers.getJSONObject(i);
        if (phoneNumbers.get(i).getContactType() != null) {
            jsonPhoneNumber.put("contactTypeId", phoneNumbers.get(i).getContactType().getId());
        }
    }
    JSONArray jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extract(schoolUserEditableVariableKeys);
    for (int i = 0; i < jsonVariableKeys.size(); i++) {
        JSONObject jsonVariableKey = jsonVariableKeys.getJSONObject(i);
        String key = jsonVariableKey.getString("variableKey");
        String value = schoolVariableDAO.findValueBySchoolAndKey(school, key);
        if (value != null)
            jsonVariableKey.put("variableValue", value);
    }
    this.setJsDataVariable(pageRequestContext, "addresses", jsonAddresses.toString());
    this.setJsDataVariable(pageRequestContext, "emails", jsonEmails.toString());
    this.setJsDataVariable(pageRequestContext, "phoneNumbers", jsonPhoneNumbers.toString());
    this.setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    this.setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("school", school);
    pageRequestContext.getRequest().setAttribute("variableKeys", schoolUserEditableVariableKeys);
    pageRequestContext.getRequest().setAttribute("schoolFields", schoolFieldDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/settings/editschool.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) SchoolVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) JSONArray(net.sf.json.JSONArray) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) JSONObject(net.sf.json.JSONObject) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 2 with SchoolFieldDAO

use of fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO 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);
}
Also used : SchoolField(fi.otavanopisto.pyramus.domainmodel.base.SchoolField) PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) BillingDetailsDAO(fi.otavanopisto.pyramus.dao.base.BillingDetailsDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) HashSet(java.util.HashSet)

Example 3 with SchoolFieldDAO

use of fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO 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);
}
Also used : SchoolField(fi.otavanopisto.pyramus.domainmodel.base.SchoolField) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO)

Example 4 with SchoolFieldDAO

use of fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO in project pyramus by otavanopisto.

the class SchoolFieldsSetupWizardViewController method save.

@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    int rowCount = NumberUtils.createInteger(requestContext.getRequest().getParameter("schoolFieldsTable.rowCount")).intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "schoolFieldsTable." + i;
        String name = requestContext.getString(colPrefix + ".name");
        schoolFieldDAO.create(name);
    }
}
Also used : SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO)

Example 5 with SchoolFieldDAO

use of fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO in project pyramus by otavanopisto.

the class SchoolsSetupWizardViewController method save.

@Override
public void save(PageRequestContext requestContext) throws SetupWizardException {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    int rowCount = requestContext.getInteger("schoolsTable.rowCount");
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "schoolsTable." + i;
        String code = requestContext.getString(colPrefix + ".code");
        String name = requestContext.getString(colPrefix + ".name");
        Long fieldId = requestContext.getLong(colPrefix + ".field");
        if (fieldId == null) {
            throw new SetupWizardException("School field is missing");
        }
        SchoolField schoolField = schoolFieldDAO.findById(fieldId);
        if (schoolField == null) {
            throw new SetupWizardException("School field is missing");
        }
        BillingDetails billingDetails = null;
        schoolDAO.create(code, name, schoolField, billingDetails);
    }
}
Also used : SchoolField(fi.otavanopisto.pyramus.domainmodel.base.SchoolField) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)

Aggregations

SchoolFieldDAO (fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO)10 SchoolField (fi.otavanopisto.pyramus.domainmodel.base.SchoolField)6 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)4 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)4 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)4 JSONArrayExtractor (fi.otavanopisto.pyramus.util.JSONArrayExtractor)4 SchoolVariableDAO (fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO)3 BillingDetails (fi.otavanopisto.pyramus.domainmodel.base.BillingDetails)3 School (fi.otavanopisto.pyramus.domainmodel.base.School)3 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)3 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)2 BillingDetailsDAO (fi.otavanopisto.pyramus.dao.base.BillingDetailsDAO)2 ContactURLTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO)2 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)2 PhoneNumberDAO (fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO)2 SchoolVariableKeyDAO (fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO)2 TagDAO (fi.otavanopisto.pyramus.dao.base.TagDAO)2 Address (fi.otavanopisto.pyramus.domainmodel.base.Address)2 ContactURLType (fi.otavanopisto.pyramus.domainmodel.base.ContactURLType)2 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)2