Skip to content

Commit

Permalink
RUtil.safeListReferenceToSet renamed to toRObjectReferenceSet
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jun 10, 2020
1 parent 5b20070 commit eb3538a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
Expand Up @@ -233,9 +233,9 @@ public static void copyFocusInformationFromJAXB(FocusType jaxb, RFocus repo, Rep
repo.setLocalityFocus(RPolyString.copyFromJAXB(jaxb.getLocality()));
repo.setCostCenter(jaxb.getCostCenter());
repo.getLinkRef().addAll(
RUtil.safeListReferenceToSet(jaxb.getLinkRef(), repo, RReferenceOwner.USER_ACCOUNT, repositoryContext.relationRegistry));
RUtil.toRObjectReferenceSet(jaxb.getLinkRef(), repo, RReferenceOwner.USER_ACCOUNT, repositoryContext.relationRegistry));
repo.getPersonaRef().addAll(
RUtil.safeListReferenceToSet(jaxb.getPersonaRef(), repo, RReferenceOwner.PERSONA, repositoryContext.relationRegistry));
RUtil.toRObjectReferenceSet(jaxb.getPersonaRef(), repo, RReferenceOwner.PERSONA, repositoryContext.relationRegistry));

if (jaxb.getActivation() != null) {
RActivation activation = new RActivation();
Expand Down
Expand Up @@ -620,13 +620,13 @@ static void copyAssignmentHolderInformationFromJAXB(AssignmentHolderType jaxb, R
copyObjectInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult);

repo.getRoleMembershipRef().addAll(
RUtil.safeListReferenceToSet(jaxb.getRoleMembershipRef(), repo, RReferenceOwner.ROLE_MEMBER, repositoryContext.relationRegistry));
RUtil.toRObjectReferenceSet(jaxb.getRoleMembershipRef(), repo, RReferenceOwner.ROLE_MEMBER, repositoryContext.relationRegistry));

repo.getDelegatedRef().addAll(
RUtil.safeListReferenceToSet(jaxb.getDelegatedRef(), repo, RReferenceOwner.DELEGATED, repositoryContext.relationRegistry));
RUtil.toRObjectReferenceSet(jaxb.getDelegatedRef(), repo, RReferenceOwner.DELEGATED, repositoryContext.relationRegistry));

repo.getArchetypeRef().addAll(
RUtil.safeListReferenceToSet(jaxb.getArchetypeRef(), repo, RReferenceOwner.ARCHETYPE, repositoryContext.relationRegistry));
RUtil.toRObjectReferenceSet(jaxb.getArchetypeRef(), repo, RReferenceOwner.ARCHETYPE, repositoryContext.relationRegistry));

for (AssignmentType assignment : jaxb.getAssignment()) {
RAssignment rAssignment = new RAssignment(repo, RAssignmentOwner.FOCUS);
Expand Down Expand Up @@ -656,7 +656,7 @@ static void copyObjectInformationFromJAXB(ObjectType jaxb, RObject repo,
.getVersion()) : 0;
repo.setVersion(version);

repo.getParentOrgRef().addAll(RUtil.safeListReferenceToSet(jaxb.getParentOrgRef(),
repo.getParentOrgRef().addAll(RUtil.toRObjectReferenceSet(jaxb.getParentOrgRef(),
repo, RReferenceOwner.OBJECT_PARENT_ORG, repositoryContext.relationRegistry));

for (TriggerType trigger : jaxb.getTrigger()) {
Expand Down
Expand Up @@ -101,7 +101,7 @@ public static void copyFromJAXB(ObjectTemplateType jaxb, RObjectTemplate repo, R

repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName()));

repo.getIncludeRef().addAll(RUtil.safeListReferenceToSet(
repo.getIncludeRef().addAll(RUtil.toRObjectReferenceSet(
jaxb.getIncludeRef(), repo, RReferenceOwner.INCLUDE, repositoryContext.relationRegistry));
}
}
Expand Up @@ -150,7 +150,7 @@ public static void copyFromJAXB(ResourceType jaxb, RResource repo, RepositoryCon
try {
if (jaxb.getBusiness() != null) {
ResourceBusinessConfigurationType business = jaxb.getBusiness();
repo.getApproverRef().addAll(RUtil.safeListReferenceToSet(business.getApproverRef(),
repo.getApproverRef().addAll(RUtil.toRObjectReferenceSet(business.getApproverRef(),
repo, RReferenceOwner.RESOURCE_BUSINESS_CONFIGURATON_APPROVER, repositoryContext.relationRegistry));
repo.setAdministrativeState(RUtil.getRepoEnumValue(business.getAdministrativeState(),
RResourceAdministrativeState.class));
Expand Down
Expand Up @@ -6,6 +6,13 @@
*/
package com.evolveum.midpoint.repo.sql.data.factory;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.data.common.Metadata;
import com.evolveum.midpoint.repo.sql.data.common.RObject;
Expand All @@ -19,13 +26,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.MetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author lazyman
*/
Expand Down Expand Up @@ -104,18 +104,24 @@ public static void fromJaxb(

if (repo instanceof RObject) {
repo.getCreateApproverRef().clear();
repo.getCreateApproverRef().addAll(RUtil.safeListReferenceToSet(jaxb.getCreateApproverRef(),
(RObject) repo, RReferenceOwner.CREATE_APPROVER, relationRegistry));
repo.getCreateApproverRef().addAll(
RUtil.toRObjectReferenceSet(jaxb.getCreateApproverRef(),
(RObject) repo, RReferenceOwner.CREATE_APPROVER, relationRegistry));
repo.getModifyApproverRef().clear();
repo.getModifyApproverRef().addAll(RUtil.safeListReferenceToSet(jaxb.getModifyApproverRef(),
(RObject) repo, RReferenceOwner.MODIFY_APPROVER, relationRegistry));
repo.getModifyApproverRef().addAll(
RUtil.toRObjectReferenceSet(jaxb.getModifyApproverRef(),
(RObject) repo, RReferenceOwner.MODIFY_APPROVER, relationRegistry));
} else {
repo.getCreateApproverRef().clear();
repo.getCreateApproverRef().addAll(safeListReferenceToSet(jaxb.getCreateApproverRef(),
(RAssignment) repo, RCReferenceOwner.CREATE_APPROVER, relationRegistry));
repo.getCreateApproverRef().addAll(
safeListReferenceToSet(
jaxb.getCreateApproverRef(), (RAssignment) repo,
RCReferenceOwner.CREATE_APPROVER, relationRegistry));
repo.getModifyApproverRef().clear();
repo.getModifyApproverRef().addAll(safeListReferenceToSet(jaxb.getModifyApproverRef(),
(RAssignment) repo, RCReferenceOwner.MODIFY_APPROVER, relationRegistry));
repo.getModifyApproverRef().addAll(
safeListReferenceToSet(
jaxb.getModifyApproverRef(), (RAssignment) repo,
RCReferenceOwner.MODIFY_APPROVER, relationRegistry));
}
}

Expand Down
Expand Up @@ -15,12 +15,14 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipException;
import javax.xml.namespace.QName;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
Expand Down Expand Up @@ -151,33 +153,26 @@ public static List<ObjectReferenceType> safeSetReferencesToList(
return list;
}

public static Set safeListReferenceToSet(List<ObjectReferenceType> list,
RObject owner, RReferenceOwner refOwner, RelationRegistry relationRegistry) {
Set<RObjectReference> set = new HashSet<>();
if (list == null || list.isEmpty()) {
return set;
}

for (ObjectReferenceType ref : list) {
RObjectReference rRef = RUtil.jaxbRefToRepo(ref, owner, refOwner, relationRegistry);
if (rRef != null) {
set.add(rRef);
}
}
return set;
public static <T extends RObject> Set<RObjectReference<T>> toRObjectReferenceSet(
List<ObjectReferenceType> list, RObject owner, RReferenceOwner refOwner, RelationRegistry relationRegistry) {
return CollectionUtils.emptyIfNull(list)
.stream()
.<RObjectReference<T>>map(
ref -> RUtil.jaxbRefToRepo(ref, owner, refOwner, relationRegistry))
.collect(Collectors.toSet());
}

public static RObjectReference jaxbRefToRepo(ObjectReferenceType reference,
RObject owner, RReferenceOwner refOwner, RelationRegistry relationRegistry) {
public static <T extends RObject> RObjectReference<T> jaxbRefToRepo(ObjectReferenceType reference,
RObject owner, RReferenceOwner refType, RelationRegistry relationRegistry) {
if (reference == null) {
return null;
}
Validate.notNull(owner, "Owner of reference must not be null.");
Validate.notNull(refOwner, "Reference owner of reference must not be null.");
Validate.notNull(refType, "Reference owner of reference must not be null.");
Validate.notEmpty(reference.getOid(), "Target oid reference must not be null.");

RObjectReference repoRef = new RObjectReference();
repoRef.setReferenceType(refOwner);
RObjectReference<T> repoRef = new RObjectReference<>();
repoRef.setReferenceType(refType);
repoRef.setOwner(owner);
RObjectReference.copyFromJAXB(reference, repoRef, relationRegistry);

Expand Down

0 comments on commit eb3538a

Please sign in to comment.