Search in sources :

Example 21 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method createAssignmentModification.

protected ContainerDelta<AssignmentType> createAssignmentModification(String roleOid, QName refType, QName relation, Consumer<AssignmentType> modificationBlock, boolean add) throws SchemaException {
    ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
    PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
    if (add) {
        assignmentDelta.addValueToAdd(cval);
    } else {
        assignmentDelta.addValueToDelete(cval);
    }
    PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
    targetRef.getValue().setOid(roleOid);
    targetRef.getValue().setTargetType(refType);
    targetRef.getValue().setRelation(relation);
    if (modificationBlock != null) {
        modificationBlock.accept(cval.asContainerable());
    }
    return assignmentDelta;
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 22 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class CertificationCaseHelper method addOrDeleteCases.

protected List<Long> addOrDeleteCases(Session session, String campaignOid, Collection<? extends ItemDelta> modifications) throws SchemaException, DtoTranslationException {
    final ItemPath casePath = new ItemPath(AccessCertificationCampaignType.F_CASE);
    boolean replacePresent = false;
    List<Long> affectedIds = new ArrayList<>();
    for (ItemDelta delta : modifications) {
        ItemPath deltaPath = delta.getPath();
        if (!casePath.isSubPathOrEquivalent(deltaPath)) {
            throw new IllegalStateException("Wrong campaign delta sneaked into updateCampaignCases: class=" + delta.getClass() + ", path=" + deltaPath);
        }
        if (deltaPath.size() == 1) {
            if (delta.getValuesToDelete() != null) {
                // todo do 'bulk' delete like delete from ... where oid=? and id in (...)
                for (PrismContainerValue value : (Collection<PrismContainerValue>) delta.getValuesToDelete()) {
                    Long id = value.getId();
                    if (id == null) {
                        throw new SchemaException("Couldn't delete certification case with null id");
                    }
                    affectedIds.add(id);
                    // TODO couldn't this cascading be done by hibernate itself?
                    Integer integerCaseId = RUtil.toInteger(id);
                    //                        Query deleteCaseReferences = session.createSQLQuery("delete from " + RCertCaseReference.TABLE +
                    //                                " where owner_owner_oid=:oid and owner_id=:id");
                    //                        deleteCaseReferences.setString("oid", campaignOid);
                    //                        deleteCaseReferences.setInteger("id", integerCaseId);
                    //                        deleteCaseReferences.executeUpdate();
                    Query deleteWorkItemReferences = session.createSQLQuery("delete from " + RCertWorkItemReference.TABLE + " where owner_owner_owner_oid=:oid and owner_owner_id=:id");
                    deleteWorkItemReferences.setString("oid", campaignOid);
                    deleteWorkItemReferences.setInteger("id", integerCaseId);
                    deleteWorkItemReferences.executeUpdate();
                    Query deleteCaseWorkItems = session.createSQLQuery("delete from " + RAccessCertificationWorkItem.TABLE + " where owner_owner_oid=:oid and owner_id=:id");
                    deleteCaseWorkItems.setString("oid", campaignOid);
                    deleteCaseWorkItems.setInteger("id", integerCaseId);
                    deleteCaseWorkItems.executeUpdate();
                    Query deleteCase = session.getNamedQuery("delete.campaignCase");
                    deleteCase.setString("oid", campaignOid);
                    deleteCase.setInteger("id", integerCaseId);
                    deleteCase.executeUpdate();
                }
            }
            // So it's safest not to provide any IDs by the client
            if (delta.getValuesToAdd() != null) {
                int currentId = generalHelper.findLastIdInRepo(session, campaignOid, "get.campaignCaseLastId") + 1;
                addCertificationCampaignCases(session, campaignOid, delta.getValuesToAdd(), currentId, affectedIds);
            }
            if (delta.getValuesToReplace() != null) {
                deleteCertificationCampaignCases(session, campaignOid);
                addCertificationCampaignCases(session, campaignOid, delta.getValuesToReplace(), 1, affectedIds);
                replacePresent = true;
            }
        }
    }
    return replacePresent ? null : affectedIds;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) Query(org.hibernate.Query) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class CertificationCaseHelper method updateLoadedCertificationWorkItem.

public AccessCertificationWorkItemType updateLoadedCertificationWorkItem(GetCertificationWorkItemResult result, // key=OID:ID
Map<String, PrismContainerValue<AccessCertificationCaseType>> casesCache, // key=OID
Map<String, PrismObject<AccessCertificationCampaignType>> campaignsCache, Collection<SelectorOptions<GetOperationOptions>> options, QueryEngine2 engine, Session session, OperationResult operationResult) throws SchemaException, QueryException {
    String campaignOid = result.getCampaignOid();
    Integer caseId = result.getCaseId();
    Integer workItemId = result.getId();
    String caseKey = campaignOid + ":" + caseId;
    PrismContainerValue<AccessCertificationCaseType> casePcv = casesCache.get(caseKey);
    if (casePcv == null) {
        ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).ownerId(campaignOid).and().id(caseId).build();
        RQuery caseQuery = engine.interpret(query, AccessCertificationCaseType.class, null, false, session);
        List<GetContainerableResult> cases = caseQuery.list();
        if (cases.size() > 1) {
            throw new IllegalStateException("More than one certification case found for campaign " + campaignOid + ", ID " + caseId);
        } else if (cases.isEmpty()) {
            // we need it, because otherwise we have only identifiers for the work item, no data
            throw new IllegalStateException("No certification case found for campaign " + campaignOid + ", ID " + caseId);
        }
        AccessCertificationCaseType _case = updateLoadedCertificationCase(cases.get(0), campaignsCache, null, session, operationResult);
        casePcv = _case.asPrismContainerValue();
        casesCache.put(caseKey, casePcv);
    }
    @SuppressWarnings({ "raw", "unchecked" }) PrismContainerValue<AccessCertificationWorkItemType> workItemPcv = (PrismContainerValue<AccessCertificationWorkItemType>) casePcv.find(new ItemPath(AccessCertificationCaseType.F_WORK_ITEM, workItemId));
    if (workItemPcv == null) {
        throw new IllegalStateException("No work item " + workItemId + " in " + casePcv);
    } else {
        return workItemPcv.asContainerable();
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) RQuery(com.evolveum.midpoint.repo.sql.query.RQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AccessCertificationWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)

Example 24 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class LookupTableHelper method addLookupTableRows.

private void addLookupTableRows(Session session, String tableOid, Collection<PrismContainerValue> values, int currentId, boolean deleteBeforeAdd) throws SchemaException {
    for (PrismContainerValue value : values) {
        LookupTableRowType rowType = new LookupTableRowType();
        rowType.setupContainerValue(value);
        if (deleteBeforeAdd) {
            deleteRowByKey(session, tableOid, rowType.getKey());
        }
        RLookupTableRow row = RLookupTableRow.toRepo(tableOid, rowType);
        row.setId(currentId);
        currentId++;
        session.save(row);
    }
}
Also used : RLookupTableRow(com.evolveum.midpoint.repo.sql.data.common.other.RLookupTableRow) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) LookupTableRowType(com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableRowType)

Example 25 with PrismContainerValue

use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.

the class AddAssignmentAspect method assignmentToDelta.

// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) {
    PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew();
    PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT);
    ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> addRoleDelta = new ContainerDelta<>(new ItemPath(), FocusType.F_ASSIGNMENT, prismContainerDefinition, prismContext);
    PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone();
    addRoleDelta.addValueToAdd(assignmentValue);
    Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext);
    return ObjectDelta.createModifyDelta(objectOid, addRoleDelta, focusClass, modelContext.getPrismContext());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ContainerDelta(com.evolveum.midpoint.prism.delta.ContainerDelta) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)59 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 Task (com.evolveum.midpoint.task.api.Task)22 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)22 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)21 Test (org.testng.annotations.Test)18 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 ArrayList (java.util.ArrayList)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 PrismObject (com.evolveum.midpoint.prism.PrismObject)10 QName (javax.xml.namespace.QName)10 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)9 PrismReference (com.evolveum.midpoint.prism.PrismReference)9 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)6 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)6