Example usage for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_INACTIVE

List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_INACTIVE

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_INACTIVE.

Prototype

int STATUS_INACTIVE

To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_INACTIVE.

Click Source Link

Usage

From source file:org.oep.cmon.admin.portlet.business.PortalUserBs.java

License:Apache License

/** 
 * This is function delete User/*from ww w. j av  a 2  s  . c om*/
 * 
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  21-March-2013  Nam Dinh    Create new
 * @param email
 * @param companyId
 * @throws SystemException 
 * @throws PortalException 
 */
public void deleteUser(String email, long companyId) throws PortalException, SystemException {
    // Check if user exists      
    User existUser = null;
    try {
        existUser = UserLocalServiceUtil.getUserByEmailAddress(companyId, email);
    } catch (Exception e) {
        // This is the problem of fucking version of LF, when an user doest not exist, it will throw
        // exception instead of return null
    }

    if (existUser != null) {
        // Deactivate user
        UserLocalServiceUtil.updateStatus(existUser.getUserId(), WorkflowConstants.STATUS_INACTIVE);
    }
}

From source file:org.oep.core.logging.action.UserActivityAction.java

License:Apache License

public void deactivateUser(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {
    long userId = ParamUtil.getLong(actionRequest, "userId");
    try {// www  . jav a 2  s  . c  o m
        UserLocalServiceUtil.updateStatus(userId, WorkflowConstants.STATUS_INACTIVE);
        SessionMessages.add(actionRequest, "org.oep.useractivity.success.deactive");
    } catch (Exception e) {
        SessionErrors.add(actionRequest, "org.oep.useractivity.error.operation.fail");
    }

    actionResponse.sendRedirect(ParamUtil.getString(actionRequest, PortletKeys.REDIRECT_PAGE));
}

From source file:org.opencps.accountmgt.service.impl.BusinessLocalServiceImpl.java

License:Open Source License

public Business addBusiness(String fullName, String enName, String shortName, String businessType,
        String idNumber, String address, String cityCode, String districtCode, String wardCode, String cityName,
        String districtName, String wardName, String telNo, String email, String representativeName,
        String representativeRole, String[] businessDomainCodes, int birthDateDay, int birthDateMonth,
        int birthDateYear, long repositoryId, String sourceFileName, String contentType, String title,
        InputStream inputStream, long size, ServiceContext serviceContext)
        throws SystemException, PortalException {

    Role roleDefault = null;//from  w  w  w  .  j  a  v  a2  s  .  c om

    try {
        roleDefault = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(),
                WebKeys.CITIZEN_BUSINESS_ROLE_NAME);
    } catch (Exception e) {
        _log.info("ROLE CITIZEN IS NULL");
    }

    long businessId = counterLocalService.increment(Business.class.getName());

    Business business = businessPersistence.create(businessId);

    Date now = new Date();

    PortletUtil.SplitName spn = PortletUtil.splitName(fullName);

    boolean autoPassword = true;
    boolean autoScreenName = true;
    boolean sendEmail = false;

    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;

    String password1 = null;
    String password2 = null;
    String screenName = null;

    //add default role
    if (Validator.isNotNull(roleDefault)) {
        roleIds = new long[] { roleDefault.getRoleId() };
    }

    UserGroup userGroup = null;
    try {
        userGroup = UserGroupLocalServiceUtil.getUserGroup(serviceContext.getCompanyId(),
                PortletPropsValues.USERMGT_USERGROUP_NAME_BUSINESS);
    } catch (Exception e) {
        _log.warn(e.getMessage());
    }

    if (userGroup == null) {
        userGroup = UserGroupLocalServiceUtil.addUserGroup(serviceContext.getUserId(),
                serviceContext.getCompanyId(), PortletPropsValues.USERMGT_USERGROUP_NAME_BUSINESS,
                StringPool.BLANK, serviceContext);

    }

    if (userGroup != null) {
        userGroupIds = new long[] { userGroup.getUserGroupId() };
    }

    password1 = PwdGenerator.getPassword();
    password2 = password1;

    Role adminRole = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(), "Administrator");
    List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());

    PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
    PermissionChecker permissionChecker;
    try {
        permissionChecker = PermissionCheckerFactoryUtil.create(adminUsers.get(0));
        PermissionThreadLocal.setPermissionChecker(permissionChecker);
    } catch (Exception e) {
        _log.error(e);
    }

    User mappingUser = userService.addUserWithWorkflow(serviceContext.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, email, 0L, StringPool.BLANK, LocaleUtil.getDefault(),
            spn.getFirstName(), spn.getMidName(), spn.getLastName(), 0, 0, true, birthDateMonth, birthDateDay,
            birthDateYear, "Business", groupIds, organizationIds, roleIds, userGroupIds,
            new ArrayList<Address>(), new ArrayList<EmailAddress>(), new ArrayList<Phone>(),
            new ArrayList<Website>(), new ArrayList<AnnouncementsDelivery>(), sendEmail, serviceContext);

    int status = WorkflowConstants.STATUS_INACTIVE;

    Organization org = OrganizationLocalServiceUtil.addOrganization(mappingUser.getUserId(), 0,
            fullName + StringPool.OPEN_PARENTHESIS + idNumber + StringPool.CLOSE_PARENTHESIS,
            OrganizationConstants.TYPE_REGULAR_ORGANIZATION, 0, 0,
            ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, enName, true, serviceContext);

    userService.addOrganizationUsers(org.getOrganizationId(), new long[] { mappingUser.getUserId() });

    mappingUser = userService.updateStatus(mappingUser.getUserId(), status);

    String[] folderNames = new String[] { PortletConstants.DestinationRoot.BUSINESS.toString(), cityName,
            districtName, wardName, String.valueOf(mappingUser.getUserId()) };

    String destination = PortletUtil.getDestinationFolder(folderNames);

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    FileEntry fileEntry = null;

    if (size > 0 && inputStream != null) {
        DLFolder dlFolder = DLFolderUtil.getTargetFolder(mappingUser.getUserId(),
                serviceContext.getScopeGroupId(), repositoryId, false, 0, destination, StringPool.BLANK, false,
                serviceContext);

        fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, dlFolder.getFolderId(), sourceFileName,
                contentType, title, StringPool.BLANK, StringPool.BLANK, inputStream, size, serviceContext);
    }

    business.setAccountStatus(PortletConstants.ACCOUNT_STATUS_REGISTERED);
    business.setAddress(address);
    business.setAttachFile(fileEntry != null ? fileEntry.getFileEntryId() : 0);
    business.setBusinessType(businessType);
    business.setCityCode(cityCode);
    business.setCompanyId(serviceContext.getCompanyId());
    business.setCreateDate(now);
    business.setDistrictCode(districtCode);
    business.setEmail(email);
    business.setEnName(enName);
    business.setGroupId(serviceContext.getScopeGroupId());
    business.setIdNumber(idNumber);

    business.setMappingOrganizationId(org != null ? org.getOrganizationId() : 0L);

    business.setMappingUserId(mappingUser.getUserId());
    business.setModifiedDate(now);
    business.setName(fullName);
    business.setRepresentativeName(representativeName);
    business.setRepresentativeRole(representativeRole);
    business.setShortName(shortName);
    business.setTelNo(telNo);
    business.setUserId(mappingUser.getUserId());

    business.setUuid(PortalUUIDUtil.generate());
    business.setWardCode(wardCode);

    business = businessPersistence.update(business);

    if (businessDomainCodes != null && businessDomainCodes.length > 0) {
        for (int b = 0; b < businessDomainCodes.length; b++) {
            BusinessDomain domain = new BusinessDomainImpl();
            domain.setBusinessId(businessId);
            domain.setBusinessDomainId(businessDomainCodes[b]);
            businessDomainPersistence.update(domain);
        }
    }

    return business;
}

From source file:org.opencps.accountmgt.service.impl.BusinessLocalServiceImpl.java

License:Open Source License

public Business updateStatus(long businessId, long userId, int accountStatus)
        throws SystemException, PortalException {

    Business business = businessPersistence.findByPrimaryKey(businessId);

    int userStatus = WorkflowConstants.STATUS_INACTIVE;

    if (accountStatus == PortletConstants.ACCOUNT_STATUS_APPROVED) {
        userStatus = WorkflowConstants.STATUS_APPROVED;
    }//from w  ww  .j a  va  2 s. c  om

    if (business.getMappingUserId() > 0) {
        userLocalService.updateStatus(business.getMappingUserId(), userStatus);
    }

    business.setUserId(userId);
    business.setModifiedDate(new Date());
    business.setAccountStatus(accountStatus);

    return businessPersistence.update(business);
}

From source file:org.opencps.accountmgt.service.impl.CitizenLocalServiceImpl.java

License:Open Source License

public Citizen addCitizen(String fullName, String personalId, int gender, int birthDateDay, int birthDateMonth,
        int birthDateYear, String address, String cityCode, String districtCode, String wardCode,
        String cityName, String districtName, String wardName, String email, String telNo, long repositoryId,
        String sourceFileName, String mimeType, String title, InputStream inputStream, long size,
        ServiceContext serviceContext) throws SystemException, PortalException {

    long citizenId = CounterLocalServiceUtil.increment(Citizen.class.getName());

    Citizen citizen = citizenPersistence.create(citizenId);

    Date now = new Date();

    Date birthDate = DateTimeUtil.getDate(birthDateDay, birthDateMonth, birthDateYear);

    PortletUtil.SplitName spn = PortletUtil.splitName(fullName);

    Role roleDefault = null;/*  w  w w  . jav a 2  s. com*/

    try {
        roleDefault = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(),
                WebKeys.CITIZEN_BUSINESS_ROLE_NAME);
    } catch (Exception e) {
        _log.info("ROLE CITIZEN IS NULL");
    }

    boolean autoPassword = true;
    boolean autoScreenName = true;
    boolean sendEmail = false;

    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;

    String password1 = null;
    String password2 = null;
    String screenName = null;

    //add default role
    if (Validator.isNotNull(roleDefault)) {
        roleIds = new long[] { roleDefault.getRoleId() };
    }

    UserGroup userGroup = null;
    try {
        userGroup = UserGroupLocalServiceUtil.getUserGroup(serviceContext.getCompanyId(),
                PortletPropsValues.USERMGT_USERGROUP_NAME_CITIZEN);
    } catch (Exception e) {
        _log.warn(e.getMessage());
    }
    if (userGroup == null) {
        userGroup = UserGroupLocalServiceUtil.addUserGroup(serviceContext.getUserId(),
                serviceContext.getCompanyId(), PortletPropsValues.USERMGT_USERGROUP_NAME_CITIZEN,
                StringPool.BLANK, serviceContext);

    }

    if (userGroup != null) {
        userGroupIds = new long[] { userGroup.getUserGroupId() };
    }
    password1 = PwdGenerator.getPassword();
    password2 = password1;

    Role adminRole = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(), "Administrator");
    List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());

    PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
    PermissionChecker permissionChecker;
    try {
        permissionChecker = PermissionCheckerFactoryUtil.create(adminUsers.get(0));
        PermissionThreadLocal.setPermissionChecker(permissionChecker);
    } catch (Exception e) {
        _log.error(e);
    }

    User mappingUser = userService.addUserWithWorkflow(serviceContext.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, email, 0L, StringPool.BLANK, LocaleUtil.getDefault(),
            spn.getFirstName(), spn.getMidName(), spn.getLastName(), 0, 0, (gender == 1), birthDateMonth,
            birthDateDay, birthDateYear, "Citizen", groupIds, organizationIds, roleIds, userGroupIds,
            new ArrayList<Address>(), new ArrayList<EmailAddress>(), new ArrayList<Phone>(),
            new ArrayList<Website>(), new ArrayList<AnnouncementsDelivery>(), sendEmail, serviceContext);

    int status = WorkflowConstants.STATUS_INACTIVE;

    mappingUser = userService.updateStatus(mappingUser.getUserId(), status);

    String[] folderNames = new String[] { PortletConstants.DestinationRoot.CITIZEN.toString(), cityName,
            districtName, wardName, String.valueOf(mappingUser.getUserId()) };

    String destination = PortletUtil.getDestinationFolder(folderNames);

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    FileEntry fileEntry = null;

    if (size > 0 && inputStream != null) {
        // Create person folder
        DLFolder dlFolder = DLFolderUtil.getTargetFolder(mappingUser.getUserId(),
                serviceContext.getScopeGroupId(), repositoryId, false, 0, destination, StringPool.BLANK, false,
                serviceContext);

        fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, dlFolder.getFolderId(), sourceFileName,
                mimeType, title, StringPool.BLANK, StringPool.BLANK, inputStream, size, serviceContext);
    }

    citizen.setAccountStatus(PortletConstants.ACCOUNT_STATUS_REGISTERED);
    citizen.setAddress(address);
    citizen.setAttachFile(fileEntry != null ? fileEntry.getFileEntryId() : 0);
    citizen.setBirthdate(birthDate);
    citizen.setCityCode(cityCode);
    citizen.setCompanyId(serviceContext.getCompanyId());
    citizen.setCreateDate(now);
    citizen.setDistrictCode(districtCode);
    citizen.setEmail(email);
    citizen.setFullName(fullName);
    citizen.setGender(gender);
    citizen.setGroupId(serviceContext.getScopeGroupId());
    citizen.setMappingUserId(mappingUser.getUserId());
    citizen.setModifiedDate(now);
    citizen.setPersonalId(personalId);
    citizen.setTelNo(telNo);
    citizen.setUserId(mappingUser.getUserId());
    citizen.setWardCode(wardCode);

    citizen.setUuid(PortalUUIDUtil.generate());

    return citizenPersistence.update(citizen);
}

From source file:org.opencps.accountmgt.service.impl.CitizenLocalServiceImpl.java

License:Open Source License

public Citizen updateStatus(long citizenId, long userId, int accountStatus)
        throws SystemException, PortalException {

    Citizen citizen = citizenPersistence.findByPrimaryKey(citizenId);

    int userStatus = WorkflowConstants.STATUS_INACTIVE;

    if (accountStatus == PortletConstants.ACCOUNT_STATUS_APPROVED) {
        userStatus = WorkflowConstants.STATUS_APPROVED;
    }/*w  w  w  .j  av  a  2 s  .  c  o  m*/

    if (citizen.getMappingUserId() > 0) {
        userLocalService.updateStatus(citizen.getMappingUserId(), userStatus);
    }

    citizen.setUserId(userId);
    citizen.setModifiedDate(new Date());
    citizen.setAccountStatus(accountStatus);

    return citizenPersistence.update(citizen);
}

From source file:org.opencps.usermgt.service.impl.EmployeeLocalServiceImpl.java

License:Open Source License

public void updateEmployee(long employeeId, int workingStatus, ServiceContext serviceContext)
        throws SystemException, PortalException {

    Employee employee = employeePersistence.findByPrimaryKey(employeeId);

    long mappingUserId = employee.getMappingUserId();

    Date now = new Date();

    if (mappingUserId > 0) {

        if (workingStatus == PortletConstants.WORKING_STATUS_ACTIVATE
                || workingStatus == PortletConstants.WORKING_STATUS_DEACTIVATE) {

            int status = WorkflowConstants.STATUS_APPROVED;

            if (workingStatus == PortletConstants.WORKING_STATUS_ACTIVATE) {
                status = WorkflowConstants.STATUS_INACTIVE;
            }/*from   w  ww .j  av a2 s  . com*/

            userLocalService.updateStatus(mappingUserId, status);

        }
    }

    workingStatus = workingStatus == PortletConstants.WORKING_STATUS_ACTIVATE ? 0 : 1;

    employee.setWorkingStatus(workingStatus);
    employee.setUserId(serviceContext.getUserId());
    employee.setGroupId(serviceContext.getScopeGroupId());
    employee.setCompanyId(serviceContext.getCompanyId());
    employee.setModifiedDate(now);

    employeePersistence.update(employee);

}