Search in sources :

Example 1 with RAccessCertificationCase

use of com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase in project midpoint by Evolveum.

the class CertificationCaseHelper method updateLoadedCampaign.

// adds cases to campaign if requested by options
public <T extends ObjectType> void updateLoadedCampaign(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Session session) throws SchemaException {
    if (!SelectorOptions.hasToLoadPath(AccessCertificationCampaignType.F_CASE, options)) {
        return;
    }
    LOGGER.debug("Loading certification campaign cases.");
    Criteria criteria = session.createCriteria(RAccessCertificationCase.class);
    criteria.add(Restrictions.eq("ownerOid", object.getOid()));
    // TODO fetch only XML representation
    List<RAccessCertificationCase> cases = criteria.list();
    if (cases == null || cases.isEmpty()) {
        return;
    }
    AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object.asObjectable();
    List<AccessCertificationCaseType> jaxbCases = campaign.getCase();
    for (RAccessCertificationCase rCase : cases) {
        AccessCertificationCaseType jaxbCase = rCase.toJAXB(prismContext);
        jaxbCases.add(jaxbCase);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase) Criteria(org.hibernate.Criteria) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 2 with RAccessCertificationCase

use of com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase in project midpoint by Evolveum.

the class CertificationCaseHelper method addCertificationCampaignCases.

public 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();
        generator.generate(caseType, PrismIdentifierGenerator.Operation.MODIFY);
        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 3 with RAccessCertificationCase

use of com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase 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 " + campaignOid + " with delta " + 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, false);
            // to avoid changing original modifications
            delta = delta.clone();
            // remove "case[id]" from the delta path
            delta.setParentPath(delta.getParentPath().tail(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();
            generator.generate(aCase, PrismIdentifierGenerator.Operation.MODIFY);
            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.isExecuteIfNoChanges(modifyOptions)) {
        Query 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, false);
            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) 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) 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 4 with RAccessCertificationCase

use of com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase in project midpoint by Evolveum.

the class CertificationCaseHelper method addCertificationCampaignCases.

public void addCertificationCampaignCases(Session session, RObject object, boolean deleteBeforeAdd) {
    if (!(object instanceof RAccessCertificationCampaign)) {
        return;
    }
    RAccessCertificationCampaign campaign = (RAccessCertificationCampaign) object;
    if (deleteBeforeAdd) {
        LOGGER.trace("Deleting existing cases for {}", campaign.getOid());
        deleteCertificationCampaignCases(session, campaign.getOid());
    }
    if (campaign.getCase() != null) {
        for (RAccessCertificationCase aCase : campaign.getCase()) {
            session.save(aCase);
        }
    }
}
Also used : RAccessCertificationCase(com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase) RAccessCertificationCampaign(com.evolveum.midpoint.repo.sql.data.common.RAccessCertificationCampaign)

Example 5 with RAccessCertificationCase

use of com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase in project midpoint by Evolveum.

the class RAccessCertificationCampaign method copyFromJAXB.

public static void copyFromJAXB(AccessCertificationCampaignType jaxb, RAccessCertificationCampaign repo, RepositoryContext repositoryContext, IdGeneratorResult generatorResult) throws DtoTranslationException {
    RObject.copyFromJAXB(jaxb, repo, repositoryContext, generatorResult);
    repo.setName(RPolyString.copyFromJAXB(jaxb.getName()));
    repo.setDefinitionRef(RUtil.jaxbRefToEmbeddedRepoRef(jaxb.getDefinitionRef(), repositoryContext.prismContext));
    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.prismContext));
    repo.setHandlerUri(jaxb.getHandlerUri());
    repo.setStart(jaxb.getStartTimestamp());
    repo.setEnd(jaxb.getEndTimestamp());
    repo.setState(RUtil.getRepoEnumValue(jaxb.getState(), RAccessCertificationCampaignState.class));
    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

RAccessCertificationCase (com.evolveum.midpoint.repo.sql.data.common.container.RAccessCertificationCase)5 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 RAccessCertificationCampaign (com.evolveum.midpoint.repo.sql.data.common.RAccessCertificationCampaign)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 RAccessCertificationCampaignState (com.evolveum.midpoint.repo.sql.data.common.enums.RAccessCertificationCampaignState)1 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 AccessCertificationCampaignType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)1 Criteria (org.hibernate.Criteria)1 Query (org.hibernate.Query)1