Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.common.bo.ou;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.common.CommonExceptionConstants;
- import org.jleaf.common.dao.OUDao;
- import org.jleaf.common.dao.OUTypeDao;
- import org.jleaf.common.entity.OU;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.Dto;
- import org.jleaf.core.GeneralConstants;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.ValidationUtil;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- *
- * Validate ou must a main Business Unit or branch ( active )
- *
- * @author NK
- * @version 1.0
- */
- @Service
- @InfoIn(value={
- @Info(name="id",description="ou id",type=Long.class)})
- @InfoOut(value = {
- @Info(name = "id", description = "ou id - auto generated", type = Long.class),
- @Info(name = "tenantId", description = "tenant id", type = Long.class),
- @Info(name = "code", description = "ou code", type = String.class),
- @Info(name = "name", description = "ou name", type = String.class),
- @Info(name = "parentId", description = "ou parent id", type = Long.class),
- @Info(name = "typeId", description = "ou type id", type = Long.class),
- @Info(name = "version", description = "version", type = Long.class),
- @Info(name = "active", description = "active status", type = String.class),
- @Info(name = "activeDateTime", description = "active date time", type = String.class),
- @Info(name = "nonActiveDateTime", description = "non active date time", type = String.class),
- @Info(name = "createUserId", description = "create user id", type = Long.class),
- @Info(name = "createDateTime", description = "create date time", type = String.class),
- @Info(name = "updateUserId", description = "update user id", type = Long.class),
- @Info(name = "updateDateTime", description = "update date time", type = String.class) })
- @ErrorList(errorKeys={CommonExceptionConstants.OUTYPE_ID_NOT_FOUND,
- CommonExceptionConstants.OU_ID_NOT_FOUND,
- CommonExceptionConstants.OU_NOT_MAIN_BUSINESS_UNIT_OR_BRANCH})
- public class ValOUAsMainBusinessUnitOrBranch extends AbstractBusinessFunction implements BusinessFunction {
- private static final Logger log = LoggerFactory.getLogger(ValOUAsMainBusinessUnitOrBranch.class);
- @Autowired
- OUTypeDao ouTypeDao;
- @Autowired
- OUDao ouDao;
- @Override
- public String getDescription(){
- return "Validate ou must a main business unit or branch ( active )";
- }
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- Dto outputDto = null;
- ValidationUtil.valDtoContainsKey(inputDto, "id");
- Long idLong = inputDto.getLong("id");
- OU ou = ouDao.findByPk(idLong);
- if (ou == null) {
- throw new CoreException(CommonExceptionConstants.OU_ID_NOT_FOUND, idLong);
- } else {
- if (!ou.getActive().equals(GeneralConstants.YES)) {
- throw new CoreException(CommonExceptionConstants.OU_NOT_ACTIVE, ou.getName());
- }
- }
- Query query = ouTypeDao.createQuery("SELECT e.flagBusinessUnit, e.flagBranch, e.flagSubBusinessUnit, e.flagAccounting FROM org.jleaf.common.entity.OUType e WHERE e.id = :id");
- query.setParameter("id", ou.getTypeId());
- log.debug("query:" + query.toString());
- List<Object[]> ouTypeList = query.getResultList();
- if (ouTypeList.size() > 0) {
- List<Dto> list = DtoUtil.createDtoListFromArray(ouTypeList, "flagBusinessUnit", "flagBranch", "flagSubBusinessUnit", "flagAccounting");
- String flagSubBusinessUnit = list.get(0).getString("flagSubBusinessUnit");
- String flagAccounting = list.get(0).getString("flagAccounting");
- if (GeneralConstants.YES.equals(flagSubBusinessUnit) || GeneralConstants.YES.equals(flagAccounting)) {
- throw new CoreException(CommonExceptionConstants.OU_NOT_MAIN_BUSINESS_UNIT_OR_BRANCH, ou.getName());
- }
- } else {
- throw new CoreException(CommonExceptionConstants.OUTYPE_ID_NOT_FOUND, ou.getTypeId());
- }
- outputDto = new Dto(ou);
- return outputDto;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement