Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2012 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kim.impl.responsibility;
 
 
 import java.util.List;
 import java.util.Map;
 
 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
 
 public class ResponsibilityServiceImpl implements ResponsibilityService {
 
     private static final Integer DEFAULT_PRIORITY_NUMBER = Integer.valueOf(1);
     private static final Log LOG = LogFactory.getLog(ResponsibilityServiceImpl.class);
 
     private RoleService roleService;
 
     @Override
     public Responsibility createResponsibility(final Responsibility responsibility)
             throws RiceIllegalArgumentExceptionRiceIllegalStateException {
         incomingParamCheck(responsibility"responsibility");
 
         if (StringUtils.isNotBlank(responsibility.getId()) && getResponsibility(responsibility.getId()) != null) {
             throw new RiceIllegalStateException("the responsibility to create already exists: " + responsibility);
         }
         List<ResponsibilityAttributeBoattrBos = Collections.emptyList();
         if (responsibility.getTemplate() != null) {
             attrBos = KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.classresponsibility.getAttributes(), responsibility.getTemplate().getKimTypeId());
         }
         ResponsibilityBo bo = ResponsibilityBo.from(responsibility);
         bo.setAttributeDetails(attrBos);
         return ResponsibilityBo.to(.save(bo));
     }
 
     @Override
     public Responsibility updateResponsibility(final Responsibility responsibility)
             throws RiceIllegalArgumentExceptionRiceIllegalStateException {
         incomingParamCheck(responsibility"responsibility");
 
         if (StringUtils.isBlank(responsibility.getId()) || getResponsibility(responsibility.getId()) == null) {
             throw new RiceIllegalStateException("the responsibility does not exist: " + responsibility);
         }
 
        List<ResponsibilityAttributeBoattrBos = Collections.emptyList();
         if (responsibility.getTemplate() != null) {
             attrBos = KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.classresponsibility.getAttributes(), responsibility.getTemplate().getKimTypeId());
        }
        ResponsibilityBo bo = ResponsibilityBo.from(responsibility);
        if (bo.getAttributeDetails() != null) {
            bo.getAttributeDetails().clear();
            bo.setAttributeDetails(attrBos);
        }
        return ResponsibilityBo.to(.save(bo));
    }
    @Override
        incomingParamCheck(id"id");
        return ResponsibilityBo.to(.findBySinglePrimaryKey(ResponsibilityBo.classid));
    }
    @Override
    public Responsibility findRespByNamespaceCodeAndName(final String namespaceCodefinal String name)
            throws RiceIllegalArgumentException {
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(name"name");
        final Map<StringStringcrit = new HashMap<StringString>();
        crit.put("namespaceCode"namespaceCode);
        crit.put("name"name);
        crit.put("active""Y");
        final Collection<ResponsibilityBobos = .findMatching(ResponsibilityBo.class, Collections.unmodifiableMap(crit));
        if (bos != null) {
            if (bos.size() > 1) {
                throw new RiceIllegalStateException("more than one Responsibility found with namespace code: " + namespaceCode + " and name: " + name);
            }
            final Iterator<ResponsibilityBoi = bos.iterator();
            return i.hasNext() ? ResponsibilityBo.to(i.next()) : null;
        }
        return null;
    }
    @Override
        incomingParamCheck(id"id");
        return ResponsibilityTemplateBo.to(.findBySinglePrimaryKey(ResponsibilityTemplateBo.classid));
    }
    @Override
    public Template findRespTemplateByNamespaceCodeAndName(final String namespaceCodefinal String namethrows RiceIllegalArgumentException {
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(name"name");
        final Map<StringStringcrit = new HashMap<StringString>();
        crit.put("namespaceCode"namespaceCode);
        crit.put("name"name);
        crit.put("active""Y");
        if (bos != null) {
            if (bos.size() > 1) {
                throw new RiceIllegalStateException("more than one Responsibility Template found with namespace code: " + namespaceCode + " and name: " + name);
            }
            final Iterator<ResponsibilityTemplateBoi = bos.iterator();
            return i.hasNext() ? ResponsibilityTemplateBo.to(i.next()) : null;
        }
        return null;
    }
    @Override
    public boolean hasResponsibility(final String principalIdfinal String namespaceCode,
            final String respNamefinal Map<StringStringqualificationthrows RiceIllegalArgumentException {
        incomingParamCheck(principalId"principalId");
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(respName"respName");
        incomingParamCheck(qualification"qualification");
        // get all the responsibility objects whose name match that requested
        final List<Responsibilityresponsibilities = Collections.singletonList(findRespByNamespaceCodeAndName(namespaceCoderespName));
        return hasResp(principalIdnamespaceCoderesponsibilitiesqualificationnull);
    }
    @Override
    public boolean hasResponsibilityByTemplate(final String principalIdfinal String namespaceCode,
            final String respTemplateNamefinal Map<StringStringqualification,
            final Map<StringStringresponsibilityDetailsthrows RiceIllegalArgumentException {
        incomingParamCheck(principalId"principalId");
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(respTemplateName"respTemplateName");
        incomingParamCheck(qualification"qualification");
        incomingParamCheck(responsibilityDetails"responsibilityDetails");
        // get all the responsibility objects whose name match that requested
        final List<Responsibilityresponsibilities = findRespsByTemplate(namespaceCoderespTemplateName);
        return hasResp(principalIdnamespaceCoderesponsibilitiesqualificationresponsibilityDetails);
    }
    private boolean hasResp(final String principalIdfinal String namespaceCode,
            final List<Responsibilityresponsibilities,
            final Map<StringStringqualification,
            final Map<StringStringresponsibilityDetailsthrows RiceIllegalArgumentException {
        // now, filter the full list by the detail passed
        final List<Stringids = new ArrayList<String>();
        for (Responsibility r : getMatchingResponsibilities(responsibilitiesresponsibilityDetails)) {
            ids.add(r.getId());
        }
        final List<StringroleIds = getRoleIdsForResponsibilities(ids);
        return .principalHasRole(principalIdroleIdsqualification);
    }
    @Override
    public List<ResponsibilityActiongetResponsibilityActions(final String namespaceCode,
            final String responsibilityNamefinal Map<StringStringqualificationthrows RiceIllegalArgumentException {
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(responsibilityName"responsibilityName");
        incomingParamCheck(qualification"qualification");
        // get all the responsibility objects whose name match that requested
        List<Responsibilityresponsibilities = Collections.singletonList(findRespByNamespaceCodeAndName(namespaceCoderesponsibilityName));
        return getRespActions(namespaceCoderesponsibilitiesqualificationnull);
    }
    @Override
            final String respTemplateNamefinal Map<StringStringqualification,
            final Map<StringStringresponsibilityDetailsthrows RiceIllegalArgumentException {
        incomingParamCheck(namespaceCode"namespaceCode");
        incomingParamCheck(respTemplateName"respTemplateName");
        incomingParamCheck(qualification"qualification");
        // get all the responsibility objects whose name match that requested
        List<Responsibilityresponsibilities = findRespsByTemplate(namespaceCoderespTemplateName);
        return getRespActions(namespaceCoderesponsibilitiesqualificationresponsibilityDetails);
    }
    private List<ResponsibilityActiongetRespActions(final String namespaceCode,
            final List<Responsibilityresponsibilities,
            final Map<StringStringqualification,
            final Map<StringStringresponsibilityDetails) {
        // now, filter the full list by the detail passed
        List<ResponsibilityapplicableResponsibilities = getMatchingResponsibilities(responsibilitiesresponsibilityDetails);
        List<ResponsibilityActionresults = new ArrayList<ResponsibilityAction>();
        for (Responsibility r : applicableResponsibilities) {
            List<StringroleIds = getRoleIdsForResponsibility(r.getId());
            results.addAll(getActionsForResponsibilityRoles(rroleIdsqualification));
        }
        return results;
    }
    private List<ResponsibilityActiongetActionsForResponsibilityRoles(Responsibility responsibilityList<StringroleIdsMap<StringStringqualification) {
        List<ResponsibilityActionresults = new ArrayList<ResponsibilityAction>();
        Collection<RoleMembershiproleMembers = .getRoleMembers(roleIds,qualification);
        for (RoleMembership rm : roleMembers) {
            // only add them to the list if the member ID has been populated
            if (StringUtils.isNotBlank(rm.getMemberId())) {
                final ResponsibilityAction.Builder rai = ResponsibilityAction.Builder.create();
                rai.setMemberRoleId((rm.getEmbeddedRoleId() == null) ? rm.getRoleId() : rm.getEmbeddedRoleId());
                rai.setRoleId(rm.getRoleId());
                rai.setQualifier(rm.getQualifier());
                final List<DelegateType.Builderbs = new ArrayList<DelegateType.Builder>();
                for (DelegateType d : rm.getDelegates()) {
                    bs.add(DelegateType.Builder.create(d));
                }
                rai.setDelegates(bs);
                rai.setResponsibilityId(responsibility.getId());
                rai.setResponsibilityName(responsibility.getName());
                rai.setResponsibilityNamespaceCode(responsibility.getNamespaceCode());
                if (..equals(rm.getType())) {
                    rai.setPrincipalId(rm.getMemberId());
                } else {
                    rai.setGroupId(rm.getMemberId());
                }
                // get associated resp resolution objects
                RoleResponsibilityAction action = getResponsibilityAction(rm.getRoleId(), responsibility.getId(), rm.getId());
                if (action == null) {
                    .error("Unable to get responsibility action record for role/responsibility/roleMember: "
                            + rm.getRoleId() + "/" + responsibility.getId() + "/" + rm.getId());
                    .error("Skipping this role member in getActionsForResponsibilityRoles()");
                    continue;
                }
                // add the data to the ResponsibilityActionInfo objects
                rai.setActionTypeCode(action.getActionTypeCode());
                rai.setActionPolicyCode(action.getActionPolicyCode());
                rai.setPriorityNumber(action.getPriorityNumber() == null ?  : action.getPriorityNumber());
                rai.setForceAction(action.isForceAction());
                rai.setParallelRoutingGroupingCode((rm.getRoleSortingCode() == null) ? "" : rm.getRoleSortingCode());
                rai.setRoleResponsibilityActionId(action.getId());
                results.add(rai.build());
            }
        }
        return Collections.unmodifiableList(results);
    }
    private RoleResponsibilityAction getResponsibilityAction(String roleIdString responsibilityIdString roleMemberId) {
        final Predicate p =
                or(
                        and(
                                equal("roleResponsibility.responsibilityId"responsibilityId),
                                equal("roleResponsibility.roleId"roleId),
                                equal("roleResponsibility.active""Y"),
                                or(
                                        equal(..roleMemberId),
                                        equal(.."*")
                                )
                        ),
                        and(
                                equal("roleResponsibilityId""*"),
                                equal(..roleMemberId)
                        )
                );
        final QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
        builder.setPredicates(p);
        final List<RoleResponsibilityActionBobos = results.getResults();
        //seems a little dubious that we are just returning the first result...
        return !bos.isEmpty() ? RoleResponsibilityActionBo.to(bos.get(0)) : null;
    }
    @Override
        incomingParamCheck(id"id");
        final List<StringroleIds = getRoleIdsForPredicate(and(equal("responsibilityId"id), equal("active""Y")));
        return Collections.unmodifiableList(roleIds);
    }
    @Override
        incomingParamCheck(queryByCriteria"queryByCriteria");
        LookupCustomizer.Builder<ResponsibilityBolc = LookupCustomizer.Builder.create();
        lc.setPredicateTransform(AttributeTransform.getInstance());
        GenericQueryResults<ResponsibilityBoresults = .lookup(ResponsibilityBo.classqueryByCriterialc.build());
        ResponsibilityQueryResults.Builder builder = ResponsibilityQueryResults.Builder.create();
        builder.setMoreResultsAvailable(results.isMoreResultsAvailable());
        builder.setTotalRowCount(results.getTotalRowCount());
        final List<Responsibility.Builderims = new ArrayList<Responsibility.Builder>();
        for (ResponsibilityBo bo : results.getResults()) {
            ims.add(Responsibility.Builder.create(bo));
        }
        builder.setResults(ims);
        return builder.build();
    }
    @Override
        incomingParamCheck(queryByCriteria"queryByCriteria");
        TemplateQueryResults.Builder builder = TemplateQueryResults.Builder.create();
        builder.setMoreResultsAvailable(results.isMoreResultsAvailable());
        builder.setTotalRowCount(results.getTotalRowCount());
        final List<Template.Builderims = new ArrayList<Template.Builder>();
        for (ResponsibilityTemplateBo bo : results.getResults()) {
            ims.add(Template.Builder.create(bo));
        }
        builder.setResults(ims);
        return builder.build();
    }

    
Compare each of the passed in responsibilities with the given responsibilityDetails. Those that match are added to the result list.
    private List<ResponsibilitygetMatchingResponsibilities(List<ResponsibilityresponsibilitiesMap<StringStringresponsibilityDetails) {
        // if no details passed, assume that all match
        if (responsibilityDetails == null || responsibilityDetails.isEmpty()) {
            return responsibilities;
        }
        final List<ResponsibilityapplicableResponsibilities = new ArrayList<Responsibility>();
        // otherwise, attempt to match the permission details
        // build a map of the template IDs to the type services
        Map<StringResponsibilityTypeServiceresponsibilityTypeServices = getResponsibilityTypeServicesByTemplateId(responsibilities);
        // build a map of permissions by template ID
        Map<StringList<Responsibility>> responsibilityMap = groupResponsibilitiesByTemplate(responsibilities);
        // loop over the different templates, matching all of the same template against the type
        // service at once
        for (Map.Entry<StringList<Responsibility>> respEntry : responsibilityMap.entrySet()) {
            ResponsibilityTypeService responsibilityTypeService = responsibilityTypeServices.get(respEntry.getKey());
            List<ResponsibilityresponsibilityInfos = respEntry.getValue();
            if (responsibilityTypeService == null) {
                responsibilityTypeService = ;
            }
            applicableResponsibilities.addAll(responsibilityTypeService.getMatchingResponsibilities(responsibilityDetailsresponsibilityInfos));
        }
        return Collections.unmodifiableList(applicableResponsibilities);
    }
        Map<StringResponsibilityTypeServiceresponsibilityTypeServices = new HashMap<StringResponsibilityTypeService>(responsibilities.size());
        for (Responsibility responsibility : responsibilities) {
            final Template t = responsibility.getTemplate();
            final KimType type = .getKimType(t.getKimTypeId());
            final String serviceName = type.getServiceName();
            if (serviceName != null) {
                ResponsibilityTypeService responsibiltyTypeService = GlobalResourceLoader.getService(serviceName);
                if (responsibiltyTypeService != null) {
                    responsibilityTypeServices.put(responsibility.getTemplate().getId(), responsibiltyTypeService);
                } else {
                    responsibilityTypeServices.put(responsibility.getTemplate().getId(), );
                }
            }
        }
        return Collections.unmodifiableMap(responsibilityTypeServices);
    }
        final Map<StringList<Responsibility>> results = new HashMap<StringList<Responsibility>>();
        for (Responsibility responsibility : responsibilities) {
            List<ResponsibilityresponsibilityInfos = results.get(responsibility.getTemplate().getId());
            if (responsibilityInfos == null) {
                responsibilityInfos = new ArrayList<Responsibility>();
                results.put(responsibility.getTemplate().getId(), responsibilityInfos);
            }
            responsibilityInfos.add(responsibility);
        }
        return Collections.unmodifiableMap(results);
    }
        final List<StringroleIds = getRoleIdsForPredicate(and(in("responsibilityId"ids.toArray()), equal("active""Y")));
        return Collections.unmodifiableList(roleIds);
    }
        final QueryByCriteria.Builder builder = QueryByCriteria.Builder.create();
        builder.setPredicates(p);
        final List<StringroleIds = new ArrayList<String>();
        for (RoleResponsibilityBo bo : qr.getResults()) {
            roleIds.add(bo.getRoleId());
        }
        return Collections.unmodifiableList(roleIds);
    }
    private List<ResponsibilityfindRespsByTemplate(final String namespaceCodefinal String templateName) {
        if (namespaceCode == null) {
            throw new RiceIllegalArgumentException("namespaceCode is null");
        }
        if (templateName == null) {
            throw new RiceIllegalArgumentException("name is null");
        }
        final Map<StringStringcrit = new HashMap<StringString>();
        crit.put("template.namespaceCode"namespaceCode); 
        crit.put("template.name"templateName); 
        crit.put("active""Y"); 
        final Collection<ResponsibilityBobos = .findMatching(ResponsibilityBo.class, Collections.unmodifiableMap(crit));
        final List<Responsibilityims = new ArrayList<Responsibility>();
        if (bos != null) {
            for (ResponsibilityBo bo : bos) {
                if (bo != null) {
                    ims.add(ResponsibilityBo.to(bo));
                }
            }
        }
        return Collections.unmodifiableList(ims);
    }
    public void setBusinessObjectService(BusinessObjectService businessObjectService) {
        this. = businessObjectService;
    }
    public void setCriteriaLookupService(final CriteriaLookupService criteriaLookupService) {
        this. = criteriaLookupService;
    }
    public void setDefaultResponsibilityTypeService(final ResponsibilityTypeService defaultResponsibilityTypeService) {
        this. = defaultResponsibilityTypeService;
    }
    public void setKimTypeInfoService(final KimTypeInfoService kimTypeInfoService) {
        this. = kimTypeInfoService;
    }
    public void setRoleService(final RoleService roleService) {
        this. = roleService;
    }
    private void incomingParamCheck(Object objectString name) {
        if (object == null) {
            throw new RiceIllegalArgumentException(name + " was null");
        } else if (object instanceof String
                && StringUtils.isBlank((Stringobject)) {
            throw new RiceIllegalArgumentException(name + " was blank");
        }
    }
New to GrepCode? Check out our FAQ X