Search in sources :

Example 1 with AccessCertificationCaseType

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

the class AccessCertificationRemediationTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    LOGGER.trace("Task run starting");
    long progress = task.getProgress();
    OperationResult opResult = new OperationResult(CLASS_DOT + "run");
    opResult.setSummarizeSuccesses(true);
    TaskRunResult runResult = new TaskRunResult();
    runResult.setOperationResult(opResult);
    if (task.getChannel() == null) {
        task.setChannel(SchemaConstants.CHANNEL_REMEDIATION_URI);
    }
    String campaignOid = task.getObjectOid();
    if (campaignOid == null) {
        LOGGER.error("No campaign OID specified in the task");
        opResult.recordFatalError("No campaign OID specified in the task");
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    opResult.addContext("campaignOid", campaignOid);
    try {
        AccessCertificationCampaignType campaign = helper.getCampaign(campaignOid, null, task, opResult);
        if (!CertCampaignTypeUtil.isRemediationAutomatic(campaign)) {
            LOGGER.error("Automatic remediation is not configured.");
            opResult.recordFatalError("Automatic remediation is not configured.");
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            return runResult;
        }
        CertificationHandler handler = certificationManager.findCertificationHandler(campaign);
        int revokedOk = 0;
        int revokedError = 0;
        List<AccessCertificationCaseType> caseList = queryHelper.searchCases(campaignOid, null, null, opResult);
        for (AccessCertificationCaseType _case : caseList) {
            if (helper.isRevoke(_case, campaign)) {
                OperationResult caseResult = opResult.createMinorSubresult(opResult.getOperation() + ".revoke");
                final Long caseId = _case.asPrismContainerValue().getId();
                caseResult.addContext("caseId", caseId);
                try {
                    handler.doRevoke(_case, campaign, task, caseResult);
                    caseHelper.markCaseAsRemedied(campaignOid, caseId, task, caseResult);
                    caseResult.computeStatus();
                    revokedOk++;
                    progress++;
                } catch (Exception e) {
                    // TODO
                    String message = "Couldn't revoke case " + caseId + ": " + e.getMessage();
                    LoggingUtils.logUnexpectedException(LOGGER, message, e);
                    caseResult.recordPartialError(message, e);
                    revokedError++;
                }
                opResult.summarize();
            }
        }
        opResult.createSubresult(CLASS_DOT + "run.statistics").recordStatus(OperationResultStatus.NOT_APPLICABLE, "Successfully revoked items: " + revokedOk + ", tried to revoke but failed: " + revokedError);
        opResult.computeStatus();
        certificationManager.closeCampaign(campaignOid, task, opResult);
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        runResult.setProgress(progress);
        LOGGER.trace("Task run stopping (campaign {})", ObjectTypeUtil.toShortString(campaign));
        return runResult;
    } catch (Exception e) {
        // TODO better error handling
        LoggingUtils.logException(LOGGER, "Error while executing remediation task handler", e);
        opResult.recordFatalError("Error while executing remediation task handler: " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setProgress(progress);
        return runResult;
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult) CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 2 with AccessCertificationCaseType

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

the class QueryInterpreter2Test method test770CaseParentFilter.

@Test
public void test770CaseParentFilter() throws Exception {
    Session session = open();
    try {
        /*
             * ### AccessCertificationCaseType: Equal(../name, 'Campaign 1')
             */
        ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(T_PARENT, F_NAME).eq("Campaign 1").build();
        String real = getInterpretedQuery2(session, AccessCertificationCaseType.class, query);
        String expected = "select\n" + "  a.ownerOid, a.id, a.fullObject\n" + "from\n" + "  RAccessCertificationCase a\n" + "    left join a.owner o\n" + "where\n" + "  (\n" + "    o.name.orig = :orig and\n" + "    o.name.norm = :norm\n" + "  )\n";
        assertEqualsIgnoreWhitespace(expected, real);
    } finally {
        close(session);
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 3 with AccessCertificationCaseType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType 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 4 with AccessCertificationCaseType

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

the class CertificationTest method checkCasesTotal.

private void checkCasesTotal(Integer expected, OperationResult result) throws SchemaException, ObjectNotFoundException {
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).build();
    List<AccessCertificationCaseType> cases = repositoryService.searchContainers(AccessCertificationCaseType.class, query, null, result);
    assertCasesFound(expected, cases, "");
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 5 with AccessCertificationCaseType

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

the class AccessCertificationRemediationTaskHandler method run.

@Override
public TaskRunResult run(@NotNull RunningTask task) {
    LOGGER.trace("Task run starting");
    OperationResult opResult = task.getResult().createSubresult(CLASS_DOT + "run");
    opResult.setSummarizeSuccesses(true);
    TaskRunResult runResult = new TaskRunResult();
    String campaignOid = task.getObjectOid();
    if (campaignOid == null) {
        LOGGER.error("No campaign OID specified in the task");
        opResult.recordFatalError("No campaign OID specified in the task");
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    opResult.addContext("campaignOid", campaignOid);
    try {
        AccessCertificationCampaignType campaign = helper.getCampaign(campaignOid, null, task, opResult);
        if (!CertCampaignTypeUtil.isRemediationAutomatic(campaign)) {
            LOGGER.error("Automatic remediation is not configured.");
            opResult.recordFatalError("Automatic remediation is not configured.");
            runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            return runResult;
        }
        CertificationHandler handler = certificationManager.findCertificationHandler(campaign);
        int revokedOk = 0;
        int revokedError = 0;
        List<AccessCertificationCaseType> caseList = queryHelper.getAllCurrentIterationCases(campaignOid, norm(campaign.getIteration()), null, opResult);
        for (AccessCertificationCaseType acase : caseList) {
            if (OutcomeUtils.isRevoke(acase, campaign)) {
                OperationResult caseResult = opResult.createMinorSubresult(opResult.getOperation() + ".revoke");
                final Long caseId = acase.asPrismContainerValue().getId();
                caseResult.addContext("caseId", caseId);
                try {
                    handler.doRevoke(acase, campaign, task, caseResult);
                    caseHelper.markCaseAsRemedied(campaignOid, caseId, task, caseResult);
                    caseResult.computeStatus();
                    revokedOk++;
                    task.incrementLegacyProgressAndStoreStatisticsIfTimePassed(opResult);
                } catch (CommonException | RuntimeException e) {
                    String message = "Couldn't revoke case " + caseId + ": " + e.getMessage();
                    LoggingUtils.logUnexpectedException(LOGGER, message, e);
                    caseResult.recordPartialError(message, e);
                    revokedError++;
                }
                opResult.summarize();
            }
        }
        opResult.createSubresult(CLASS_DOT + "run.statistics").recordStatus(OperationResultStatus.NOT_APPLICABLE, "Successfully revoked items: " + revokedOk + ", tried to revoke but failed: " + revokedError);
        opResult.computeStatus();
        certificationManager.closeCampaign(campaignOid, task, opResult);
        runResult.setOperationResultStatus(OperationResultStatus.SUCCESS);
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        LOGGER.trace("Task run stopping (campaign {})", ObjectTypeUtil.toShortString(campaign));
        return runResult;
    } catch (Exception e) {
        // TODO better error handling
        LoggingUtils.logException(LOGGER, "Error while executing remediation task handler", e);
        opResult.recordFatalError("Error while executing remediation task handler: " + e.getMessage(), e);
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) CommonException(com.evolveum.midpoint.util.exception.CommonException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

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