Search in sources :

Example 6 with UserRequest

use of org.jaffa.applications.jaffa.modules.user.domain.UserRequest in project jaffa-framework by jaffa-projects.

the class UserRequestMaintenanceTx method create.

// .//GEN-END:_prevalidateCreate_1_be
// .//GEN-BEGIN:_create_1_be
/**
 * Persists a new instance of UserRequest.
 * @param input The new values for the domain object.
 * @throws ApplicationExceptions This will be thrown if the input contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The object details.
 */
public UserRequestMaintenanceRetrieveOutDto create(UserRequestMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + (input != null ? input.toString() : null));
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Do not allow a Duplicate record
        duplicateCheck(uow, input);
        // Validate the foreign objects
        validateForeignObjects(uow, input);
        // Create the domain object
        UserRequest domain = createDomain(uow, input, false);
        uow.add(domain);
        // Perform post create processing
        postCreate(uow, input, domain, false);
        // Commit the changes
        uow.commit();
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Successfully created the domain object. Now retrieving the object details.");
        // Build the outbound dto by performing a retrieve
        UserRequestMaintenanceRetrieveInDto retrieveInDto = new UserRequestMaintenanceRetrieveInDto();
        retrieveInDto.setHeaderDto(input.getHeaderDto());
        retrieveInDto.setRequestId(input.getRequestId());
        UserRequestMaintenanceRetrieveOutDto output = retrieve(retrieveInDto);
        return output;
    } catch (FrameworkException e) {
        // If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
        if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
            throw (ApplicationExceptions) e.getCause();
        } else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
            ApplicationExceptions appExps = new ApplicationExceptions();
            appExps.add((ApplicationException) e.getCause());
            throw appExps;
        } else
            throw e;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Example 7 with UserRequest

use of org.jaffa.applications.jaffa.modules.user.domain.UserRequest in project jaffa-framework by jaffa-projects.

the class UserRequestLookupTx method buildDto.

// .//GEN-END:_buildCriteria_3_be
// .//GEN-BEGIN:_buildDto_1_be
private UserRequestLookupOutDto buildDto(UOW uow, Collection results, UserRequestLookupInDto input) throws UOWException {
    UserRequestLookupOutDto output = new UserRequestLookupOutDto();
    int maxRecords = input.getMaxRecords() != null ? input.getMaxRecords().intValue() : 0;
    int counter = 0;
    for (Iterator i = results.iterator(); i.hasNext(); ) {
        if (++counter > maxRecords && maxRecords > 0) {
            output.setMoreRecordsExist(Boolean.TRUE);
            break;
        }
        UserRequestLookupOutRowDto row = new UserRequestLookupOutRowDto();
        UserRequest userRequest = (UserRequest) i.next();
        // .//GEN-END:_buildDto_1_be
        // Add custom code before all the setters //GEN-FIRST:_buildDto_1
        // .//GEN-LAST:_buildDto_1
        // .//GEN-BEGIN:_buildDto_RequestId_1_be
        row.setRequestId(userRequest.getRequestId());
        // .//GEN-END:_buildDto_RequestId_1_be
        // .//GEN-BEGIN:_buildDto_UserName_1_be
        row.setUserName(userRequest.getUserName());
        // .//GEN-END:_buildDto_UserName_1_be
        // .//GEN-BEGIN:_buildDto_FirstName_1_be
        row.setFirstName(userRequest.getFirstName());
        // .//GEN-END:_buildDto_FirstName_1_be
        // .//GEN-BEGIN:_buildDto_LastName_1_be
        row.setLastName(userRequest.getLastName());
        // .//GEN-END:_buildDto_LastName_1_be
        // .//GEN-BEGIN:_buildDto_Password_1_be
        row.setPassword(userRequest.getPassword());
        // .//GEN-END:_buildDto_Password_1_be
        // .//GEN-BEGIN:_buildDto_EMailAddress_1_be
        row.setEMailAddress(userRequest.getEMailAddress());
        // .//GEN-END:_buildDto_EMailAddress_1_be
        // .//GEN-BEGIN:_buildDto_SecurityQuestion_1_be
        row.setSecurityQuestion(userRequest.getSecurityQuestion());
        // .//GEN-END:_buildDto_SecurityQuestion_1_be
        // .//GEN-BEGIN:_buildDto_SecurityAnswer_1_be
        row.setSecurityAnswer(userRequest.getSecurityAnswer());
        // .//GEN-END:_buildDto_SecurityAnswer_1_be
        // .//GEN-BEGIN:_buildDto_Remarks_1_be
        row.setRemarks(userRequest.getRemarks());
        // .//GEN-END:_buildDto_Remarks_1_be
        // .//GEN-BEGIN:_buildDto_CreatedOn_1_be
        row.setCreatedOn(userRequest.getCreatedOn());
        // .//GEN-END:_buildDto_CreatedOn_1_be
        // .//GEN-BEGIN:_buildDto_ProcessedDatetime_1_be
        row.setProcessedDatetime(userRequest.getProcessedDatetime());
        // .//GEN-END:_buildDto_ProcessedDatetime_1_be
        // .//GEN-BEGIN:_buildDto_ProcessedUserId_1_be
        row.setProcessedUserId(userRequest.getProcessedUserId());
        // .//GEN-END:_buildDto_ProcessedUserId_1_be
        // .//GEN-BEGIN:_buildDto_Status_1_be
        row.setStatus(userRequest.getStatus());
        // .//GEN-END:_buildDto_Status_1_be
        // Add custom code to pass values to the dto //GEN-FIRST:_buildDto_2
        // .//GEN-LAST:_buildDto_2
        // .//GEN-BEGIN:_buildDto_3_be
        output.addRows(row);
    }
    return output;
}
Also used : UserRequestLookupOutDto(org.jaffa.applications.jaffa.modules.user.components.userrequestlookup.dto.UserRequestLookupOutDto) UserRequestLookupOutRowDto(org.jaffa.applications.jaffa.modules.user.components.userrequestlookup.dto.UserRequestLookupOutRowDto) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Example 8 with UserRequest

use of org.jaffa.applications.jaffa.modules.user.domain.UserRequest in project jaffa-framework by jaffa-projects.

the class UserRequestMaintenanceTx method prevalidateUpdate.

// .//GEN-END:_retrieve_1_be
// .//GEN-BEGIN:_prevalidateUpdate_1_be
/**
 * This method is used to perform prevalidations before updating an existing instance of UserRequest.
 * @param input The new values for the domain object.
 * @throws ApplicationExceptions This will be thrown if the input contains invalid data.
 * @throws FrameworkException Indicates some system error.
 * @return The object details.
 */
public UserRequestMaintenancePrevalidateOutDto prevalidateUpdate(UserRequestMaintenanceUpdateInDto input) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        // Print Debug Information for the input
        if (log.isDebugEnabled())
            log.debug("Input: " + (input != null ? input.toString() : null));
        // create the UOW
        uow = new UOW();
        // Preprocess the input
        preprocess(uow, input);
        // Retrieve the object
        UserRequest domain = load(uow, input);
        // Validate the foreign objects
        validateForeignObjects(uow, input);
        // Update the domain object
        updateDomain(uow, input, domain, true);
        // Build the outbound dto
        UserRequestMaintenancePrevalidateOutDto output = createPrevalidateOutDto(uow, domain, input);
        // Print Debug Information for the output
        if (log.isDebugEnabled())
            log.debug("Output: " + (output != null ? output.toString() : null));
        return output;
    } catch (FrameworkException e) {
        // If it is, then re-throw as ApplicationsExceptions, else throw the FrameworkException.
        if (e.getCause() != null && e.getCause() instanceof ApplicationExceptions) {
            throw (ApplicationExceptions) e.getCause();
        } else if (e.getCause() != null && e.getCause() instanceof ApplicationException) {
            ApplicationExceptions appExps = new ApplicationExceptions();
            appExps.add((ApplicationException) e.getCause());
            throw appExps;
        } else
            throw e;
    } finally {
        if (uow != null)
            uow.rollback();
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) FrameworkException(org.jaffa.exceptions.FrameworkException) UOW(org.jaffa.persistence.UOW) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Example 9 with UserRequest

use of org.jaffa.applications.jaffa.modules.user.domain.UserRequest in project jaffa-framework by jaffa-projects.

the class UserRequestMaintenanceTx method load.

// .//GEN-END:_preprocessDelete_2_be
// .//GEN-BEGIN:_loadDelete_1_be
/**
 * Retrieve the domain object.
 */
private UserRequest load(UOW uow, UserRequestMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
    UserRequest domain = null;
    Criteria criteria = new Criteria();
    criteria.setTable(UserRequestMeta.getName());
    // .//GEN-END:_loadDelete_1_be
    // Add custom criteria //GEN-FIRST:_loadDelete_1
    // .//GEN-LAST:_loadDelete_1
    // .//GEN-BEGIN:_loadDelete_2_be
    criteria.addCriteria(UserRequestMeta.REQUEST_ID, input.getRequestId());
    criteria.setLocking(Criteria.LOCKING_PARANOID);
    Iterator itr = uow.query(criteria).iterator();
    if (itr.hasNext())
        domain = (UserRequest) itr.next();
    // .//GEN-BEGIN:_loadDelete_3_be
    if (domain == null) {
        ApplicationExceptions appExps = new ApplicationExceptions();
        appExps.add(new DomainObjectNotFoundException(UserRequestMeta.getLabelToken()));
        throw appExps;
    }
    return domain;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) Criteria(org.jaffa.persistence.Criteria) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Example 10 with UserRequest

use of org.jaffa.applications.jaffa.modules.user.domain.UserRequest in project jaffa-framework by jaffa-projects.

the class UserRequestMaintenanceTx method postCreate.

// .//GEN-END:_createDomain_3_be
// .//GEN-BEGIN:_postCreate_1_be
/**
 * This method is invoked after the domain object has been created.
 */
private void postCreate(UOW uow, UserRequestMaintenanceCreateInDto input, UserRequest domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
    // .//GEN-END:_postCreate_1_be
    // Add custom code //GEN-FIRST:_postCreate_1
    EmailerBean email = new EmailerBean();
    UserRequest domainCreated = new UserRequest();
    Criteria criteria = new Criteria();
    criteria.setTable(UserRequestMeta.getName());
    log.debug("This is the dto's final value" + input.getUrl());
    criteria.addCriteria(UserRequestMeta.USER_NAME, domain.getUserName());
    criteria.addCriteria(UserRequestMeta.FIRST_NAME, domain.getFirstName());
    criteria.addCriteria(UserRequestMeta.LAST_NAME, domain.getLastName());
    criteria.addCriteria(UserRequestMeta.CREATED_ON, domain.getCreatedOn());
    Iterator itr = uow.query(criteria).iterator();
    if (itr.hasNext())
        domainCreated = (UserRequest) itr.next();
    if (domainCreated != null) {
        try {
            String url = input.getUrl() + domainCreated.getRequestId();
            url = replaceAll(url, "Jaffa.User", "Jaffa.Admin");
            String[] to = new String[] { "jonny.reid@mirotechnologies.com" };
            email.sendMail(to, "request for user account", url);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
    input.setRequestId(domainCreated.getRequestId());
// .//GEN-LAST:_postCreate_1
// .//GEN-BEGIN:_postCreate_2_be
}
Also used : MessagingException(javax.mail.MessagingException) EmailerBean(org.jaffa.util.EmailerBean) Criteria(org.jaffa.persistence.Criteria) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Aggregations

UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)16 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)10 UOW (org.jaffa.persistence.UOW)6 ApplicationException (org.jaffa.exceptions.ApplicationException)5 FrameworkException (org.jaffa.exceptions.FrameworkException)5 Criteria (org.jaffa.persistence.Criteria)5 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)3 ValidationException (org.jaffa.datatypes.ValidationException)2 EmailerBean (org.jaffa.util.EmailerBean)2 Iterator (java.util.Iterator)1 MessagingException (javax.mail.MessagingException)1 UserRole (org.jaffa.applications.jaffa.modules.admin.domain.UserRole)1 UserRequestFinderOutDto (org.jaffa.applications.jaffa.modules.user.components.userrequestfinder.dto.UserRequestFinderOutDto)1 UserRequestFinderOutRowDto (org.jaffa.applications.jaffa.modules.user.components.userrequestfinder.dto.UserRequestFinderOutRowDto)1 UserRequestLookupOutDto (org.jaffa.applications.jaffa.modules.user.components.userrequestlookup.dto.UserRequestLookupOutDto)1 UserRequestLookupOutRowDto (org.jaffa.applications.jaffa.modules.user.components.userrequestlookup.dto.UserRequestLookupOutRowDto)1 UserRequestViewerOutDto (org.jaffa.applications.jaffa.modules.user.components.userrequestviewer.dto.UserRequestViewerOutDto)1