Search in sources :

Example 36 with AccessCertificationCaseType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.

the class CertificationCaseHelper method updateCasesContent.

private void updateCasesContent(Session session, String campaignOid, Collection<? extends ItemDelta> modifications, List<Long> casesAddedOrDeleted, RepoModifyOptions modifyOptions) throws SchemaException, ObjectNotFoundException, DtoTranslationException {
    Set<Long> casesModified = new HashSet<>();
    for (ItemDelta delta : modifications) {
        ItemPath deltaPath = delta.getPath();
        if (deltaPath.size() > 1) {
            LOGGER.trace("Updating campaign {} with delta {}", campaignOid, delta);
            // should start with "case[id]"
            long id = checkPathSanity(deltaPath, casesAddedOrDeleted);
            Query<?> query = session.getNamedQuery("get.campaignCase");
            query.setString("ownerOid", campaignOid);
            query.setInteger("id", (int) id);
            byte[] fullObject = (byte[]) query.uniqueResult();
            if (fullObject == null) {
                throw new ObjectNotFoundException("Couldn't update cert campaign " + campaignOid + " + by delta with path " + deltaPath + " - specified case does not exist");
            }
            AccessCertificationCaseType aCase = RAccessCertificationCase.createJaxb(fullObject, prismContext);
            // to avoid changing original modifications
            delta = delta.clone();
            // remove "case[id]" from the delta path
            delta.setParentPath(delta.getParentPath().rest(2));
            delta.applyTo(aCase.asPrismContainerValue());
            // we need to generate IDs but we (currently) do not use that for setting "isTransient" flag
            PrismIdentifierGenerator generator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
            generator.generate(aCase);
            RAccessCertificationCase rCase = RAccessCertificationCase.toRepo(campaignOid, aCase, createRepositoryContext());
            session.merge(rCase);
            LOGGER.trace("Access certification case {} merged", rCase);
            casesModified.add(aCase.getId());
        }
    }
    // refresh campaign cases, if requested
    if (RepoModifyOptions.isForceReindex(modifyOptions)) {
        // noinspection unchecked
        Query<Object> query = session.getNamedQuery("get.campaignCases");
        query.setString("ownerOid", campaignOid);
        List<Object> cases = query.list();
        for (Object o : cases) {
            if (!(o instanceof byte[])) {
                throw new IllegalStateException("Certification case: expected byte[], got " + o.getClass());
            }
            byte[] fullObject = (byte[]) o;
            AccessCertificationCaseType aCase = RAccessCertificationCase.createJaxb(fullObject, prismContext);
            Long id = aCase.getId();
            if (id != null && casesAddedOrDeleted != null && !casesAddedOrDeleted.contains(id) && !casesModified.contains(id)) {
                RAccessCertificationCase rCase = RAccessCertificationCase.toRepo(campaignOid, aCase, createRepositoryContext());
                session.merge(rCase);
                LOGGER.trace("Access certification case {} refreshed", rCase);
            }
        }
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase) PrismObject(com.evolveum.midpoint.prism.PrismObject) RObject(com.evolveum.midpoint.repo.sql.data.common.RObject) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 37 with AccessCertificationCaseType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.

the class CertificationCaseHelper method addCertificationCampaignCases.

private void addCertificationCampaignCases(Session session, String campaignOid, Collection<PrismContainerValue> values, int currentId, List<Long> affectedIds) throws DtoTranslationException {
    for (PrismContainerValue value : values) {
        AccessCertificationCaseType caseType = new AccessCertificationCaseType();
        caseType.setupContainerValue(value);
        if (caseType.getId() == null) {
            caseType.setId((long) currentId);
            currentId++;
        }
        // we need to generate IDs but we (currently) do not use that for setting "isTransient" flag
        PrismIdentifierGenerator generator = new PrismIdentifierGenerator(PrismIdentifierGenerator.Operation.MODIFY);
        generator.generate(caseType);
        RAccessCertificationCase row = RAccessCertificationCase.toRepo(campaignOid, caseType, createRepositoryContext());
        row.setId(RUtil.toInteger(caseType.getId()));
        affectedIds.add(caseType.getId());
        session.save(row);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase)

Example 38 with AccessCertificationCaseType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.

the class RAccessCertificationCase method toRepo.

private static void toRepo(RAccessCertificationCase rCase, AccessCertificationCaseType case1, RepositoryContext context) throws DtoTranslationException {
    // we don't try to advise hibernate - let it do its work, even if it would cost some SELECTs
    rCase.setTransient(null);
    rCase.setId(RUtil.toInteger(case1.getId()));
    rCase.setObjectRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getObjectRef(), context.relationRegistry));
    rCase.setTargetRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getTargetRef(), context.relationRegistry));
    rCase.setTenantRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getTenantRef(), context.relationRegistry));
    rCase.setOrgRef(RUtil.jaxbRefToEmbeddedRepoRef(case1.getOrgRef(), context.relationRegistry));
    if (case1.getActivation() != null) {
        RActivation activation = new RActivation();
        RActivation.fromJaxb(case1.getActivation(), activation);
        rCase.setActivation(activation);
    }
    for (AccessCertificationWorkItemType workItem : case1.getWorkItem()) {
        rCase.getWorkItems().add(RAccessCertificationWorkItem.toRepo(rCase, workItem, context));
    }
    rCase.setReviewRequestedTimestamp(case1.getCurrentStageCreateTimestamp());
    rCase.setReviewDeadline(case1.getCurrentStageDeadline());
    rCase.setRemediedTimestamp(case1.getRemediedTimestamp());
    rCase.setCurrentStageOutcome(case1.getCurrentStageOutcome());
    rCase.setIteration(norm(case1.getIteration()));
    rCase.setStageNumber(case1.getStageNumber());
    rCase.setOutcome(case1.getOutcome());
    // noinspection unchecked
    PrismContainerValue<AccessCertificationCaseType> cvalue = case1.asPrismContainerValue();
    String serializedForm;
    try {
        serializedForm = context.prismContext.serializerFor(context.configuration.getFullObjectFormat()).serialize(cvalue, SchemaConstantsGenerated.C_VALUE);
    } catch (SchemaException e) {
        throw new IllegalStateException("Couldn't serialize certification case to string", e);
    }
    LOGGER.trace("RAccessCertificationCase full object\n{}", serializedForm);
    byte[] fullObject = RUtil.getBytesFromSerializedForm(serializedForm, false);
    rCase.setFullObject(fullObject);
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RActivation(com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation) AccessCertificationWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)

Example 39 with AccessCertificationCaseType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType in project midpoint by Evolveum.

the class RAccessCertificationCampaign method copyFromJAXB.

// dynamically called
public static void copyFromJAXB(AccessCertificationCampaignType jaxb, RAccessCertificationCampaign repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    copyAssignmentHolderInformationFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setNameCopy(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setDefinitionRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getDefinitionRef(), repositoryContext.relationRegistry));
    List<AccessCertificationCaseType> cases = jaxb.getCase();
    if (!cases.isEmpty()) {
        for (AccessCertificationCaseType case1 : cases) {
            RAccessCertificationCase rCase = RAccessCertificationCase.toRepo(repo, case1, repositoryContext);
            // redundant?
            rCase.setTransient(generatorResult.isTransient(case1.asPrismContainerValue()));
            repo.getCase().add(rCase);
        }
    }
    repo.setOwnerRefCampaign(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getOwnerRef(), repositoryContext.relationRegistry));
    repo.setHandlerUri(jaxb.getHandlerUri());
    repo.setStart(jaxb.getStartTimestamp());
    repo.setEnd(jaxb.getEndTimestamp());
    repo.setState(RUtil.getRepoEnumValue(jaxb.getState(), RAccessCertificationCampaignState.class));
    repo.setIteration(norm(jaxb.getIteration()));
    repo.setStageNumber(jaxb.getStageNumber());
}
Also used : RAccessCertificationCampaignState(com.evolveum.midpoint.repo.sql.data.common.enums.RAccessCertificationCampaignState) AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase)

Aggregations

AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)31 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)11 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)10 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)6 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 RepositoryService (com.evolveum.midpoint.repo.api.RepositoryService)5 Task (com.evolveum.midpoint.task.api.Task)5 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)4 ObjectTypeUtil (com.evolveum.midpoint.schema.util.ObjectTypeUtil)4 java.util (java.util)4 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.testng.annotations.Test)4 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)3