Search in sources :

Example 21 with AccessCertificationCampaignType

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

the class CertHelper method appendStatistics.

public void appendStatistics(StringBuilder sb, AccessCertificationCampaignType campaign, Task task, OperationResult result) {
    AccessCertificationCasesStatisticsType stat;
    try {
        stat = certificationManager.getCampaignStatistics(campaign.getOid(), false, task, result);
    } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | ObjectAlreadyExistsException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get campaign statistics", e);
        sb.append("Couldn't get campaign statistics because of ").append(e);
        return;
    }
    int all = stat.getMarkedAsAccept() + stat.getMarkedAsRevoke() + stat.getMarkedAsReduce() + stat.getMarkedAsNotDecide() + stat.getWithoutResponse();
    sb.append("Number of cases:\t").append(all);
    sb.append("\nMarked as ACCEPT:\t").append(stat.getMarkedAsAccept());
    sb.append("\nMarked as REVOKE:\t").append(stat.getMarkedAsRevoke()).append(" (remedied: ").append(stat.getMarkedAsRevokeAndRemedied()).append(")");
    sb.append("\nMarked as REDUCE:\t").append(stat.getMarkedAsReduce()).append(" (remedied: ").append(stat.getMarkedAsReduceAndRemedied()).append(")");
    sb.append("\nMarked as NOT DECIDED:\t").append(stat.getMarkedAsNotDecide());
    sb.append("\nNo response:\t\t").append(stat.getWithoutResponse());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) AccessCertificationCasesStatisticsType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCasesStatisticsType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 22 with AccessCertificationCampaignType

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

the class ReportFunctions method searchCertificationDefinitions.

// TODO implement if needed
//    <O extends Containerable> RefFilter createReferenceEqualFilter(QName propertyName, Class<O> type, String... oids) {
//        return RefFilter.createReferenceEqual(propertyName, type, prismContext, oids);
//    }
//    <O extends Containerable> RefFilter createReferenceEqualFilter(ItemPath propertyPath, Class<O> type, String... oids) throws SchemaException {
//        return RefFilter.createReferenceEqual(propertyPath, type, prismContext, oids);
//    }
//    Object parseObjectFromXML (String xml) throws SchemaException {
//        return prismContext.parserFor(xml).xml().parseAnyData();
//    }
/**
     * Retrieves all definitions.
     * Augments them by count of campaigns (all + open ones).
     *
     * TODO query parameters, customizable sorting
     * definitions and campaigns counts are expected to be low, so we can afford to go through all of them here
     */
public Collection<PrismObject<AccessCertificationDefinitionForReportType>> searchCertificationDefinitions() throws ConfigurationException, SchemaException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
    Task task = taskManager.createTaskInstance();
    OperationResult result = task.getResult();
    Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createResolveNames());
    List<PrismObject<AccessCertificationDefinitionType>> definitions = model.searchObjects(AccessCertificationDefinitionType.class, null, options, task, result);
    final Map<String, PrismObject<AccessCertificationDefinitionForReportType>> definitionsForReportMap = new HashMap<>();
    for (PrismObject<AccessCertificationDefinitionType> definition : definitions) {
        // create subclass with the values copied from the superclass
        PrismObject<AccessCertificationDefinitionForReportType> definitionForReport = prismContext.createObjectable(AccessCertificationDefinitionForReportType.class).asPrismObject();
        for (Item<?, ?> item : definition.getValue().getItems()) {
            definitionForReport.getValue().add(item.clone());
        }
        definitionsForReportMap.put(definition.getOid(), definitionForReport);
    }
    ResultHandler<AccessCertificationCampaignType> handler = (campaignObject, parentResult) -> {
        AccessCertificationCampaignType campaign = campaignObject.asObjectable();
        if (campaign.getDefinitionRef() != null) {
            String definitionOid = campaign.getDefinitionRef().getOid();
            PrismObject<AccessCertificationDefinitionForReportType> definitionObject = definitionsForReportMap.get(definitionOid);
            if (definitionObject != null) {
                AccessCertificationDefinitionForReportType definition = definitionObject.asObjectable();
                int campaigns = definition.getCampaigns() != null ? definition.getCampaigns() : 0;
                definition.setCampaigns(campaigns + 1);
                AccessCertificationCampaignStateType state = campaign.getState();
                if (state != AccessCertificationCampaignStateType.CREATED && state != CLOSED) {
                    int openCampaigns = definition.getOpenCampaigns() != null ? definition.getOpenCampaigns() : 0;
                    definition.setOpenCampaigns(openCampaigns + 1);
                }
            }
        }
        return true;
    };
    model.searchObjectsIterative(AccessCertificationCampaignType.class, null, handler, null, task, result);
    List<PrismObject<AccessCertificationDefinitionForReportType>> rv = new ArrayList<>(definitionsForReportMap.values());
    Collections.sort(rv, (o1, o2) -> {
        String n1 = o1.asObjectable().getName().getOrig();
        String n2 = o2.asObjectable().getName().getOrig();
        if (n1 == null) {
            n1 = "";
        }
        return n1.compareTo(n2);
    });
    for (PrismObject<AccessCertificationDefinitionForReportType> defObject : rv) {
        AccessCertificationDefinitionForReportType def = defObject.asObjectable();
        if (def.getCampaigns() == null) {
            def.setCampaigns(0);
        }
        if (def.getOpenCampaigns() == null) {
            def.setOpenCampaigns(0);
        }
    }
    return rv;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) F_STATE(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType.F_STATE) Trace(com.evolveum.midpoint.util.logging.Trace) F_NAME(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType.F_NAME) TaskManager(com.evolveum.midpoint.task.api.TaskManager) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) AuditEventStage(com.evolveum.midpoint.audit.api.AuditEventStage) RetrieveOption(com.evolveum.midpoint.schema.RetrieveOption) AuditEventRecord(com.evolveum.midpoint.audit.api.AuditEventRecord) CLOSED(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType.CLOSED) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) AuditService(com.evolveum.midpoint.audit.api.AuditService) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) Task(com.evolveum.midpoint.task.api.Task) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) AuditEventTypeType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventTypeType) ModelService(com.evolveum.midpoint.model.api.ModelService) QueryBuilder(com.evolveum.midpoint.prism.query.builder.QueryBuilder) AuditEventType(com.evolveum.midpoint.audit.api.AuditEventType) AuditEventStageType(com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Entry(java.util.Map.Entry) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QName(javax.xml.namespace.QName) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

Example 23 with AccessCertificationCampaignType

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

the class SimpleCampaignNotifier method getBody.

@Override
protected String getBody(Event event, GeneralNotifierType generalNotifierType, String transport, Task task, OperationResult result) {
    StringBuilder body = new StringBuilder();
    CertCampaignEvent campaignEvent = (CertCampaignEvent) event;
    AccessCertificationCampaignType campaign = campaignEvent.getCampaign();
    body.append("Campaign ");
    body.append(certHelper.getCampaignNameAndOid(campaignEvent));
    body.append(" was ");
    if (campaignEvent.isAdd()) {
        body.append("STARTED");
    } else if (campaignEvent.isDelete()) {
        body.append("CLOSED");
    } else {
        throw new IllegalStateException("Unexpected campaign event type: neither ADD nor DELETE");
    }
    body.append(".\n\n");
    // the event is generated in the real time
    body.append("Time: ").append(new Date());
    body.append("\nRequester: ").append(formatRequester(event, result));
    body.append("\nOperation status: ").append(certHelper.formatStatus(campaignEvent));
    body.append("\n\nCurrent state: ").append(certHelper.formatState(campaignEvent));
    body.append("\n\n");
    certHelper.appendStatistics(body, campaign, task, result);
    body.append("\n\n");
    functions.addRequesterAndChannelInformation(body, event, result);
    return body.toString();
}
Also used : CertCampaignEvent(com.evolveum.midpoint.notifications.api.events.CertCampaignEvent) Date(java.util.Date) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 24 with AccessCertificationCampaignType

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

the class CertificationCaseHelper method updateLoadedCertificationCase.

// TODO find a better name
public AccessCertificationCaseType updateLoadedCertificationCase(GetContainerableResult result, Map<String, PrismObject<AccessCertificationCampaignType>> ownersMap, Collection<SelectorOptions<GetOperationOptions>> options, Session session, OperationResult operationResult) throws SchemaException {
    AccessCertificationCaseType aCase = RAccessCertificationCase.createJaxb(result.getFullObject(), prismContext, false);
    generalHelper.validateContainerable(aCase, AccessCertificationCaseType.class);
    String ownerOid = result.getOwnerOid();
    PrismObject<AccessCertificationCampaignType> campaign = resolveCampaign(ownerOid, ownersMap, session, operationResult);
    if (campaign != null && !campaign.asObjectable().getCase().contains(aCase)) {
        campaign.asObjectable().getCase().add(aCase);
    }
    return aCase;
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 25 with AccessCertificationCampaignType

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

the class CertificationTest method test730CurrentUnansweredCases.

@Test
public void test730CurrentUnansweredCases() throws Exception {
    OperationResult result = new OperationResult("test730CurrentUnansweredCases");
    ObjectQuery query = QueryBuilder.queryFor(AccessCertificationCaseType.class, prismContext).item(AccessCertificationCaseType.F_STAGE_NUMBER).eq().item(T_PARENT, AccessCertificationCampaignType.F_STAGE_NUMBER).and().item(T_PARENT, F_STATE).eq(IN_REVIEW_STAGE).and().exists(F_WORK_ITEM).block().item(F_CLOSE_TIMESTAMP).isNull().and().block().item(F_OUTPUT, F_OUTCOME).isNull().endBlock().endBlock().build();
    List<AccessCertificationCaseType> cases = repositoryService.searchContainers(AccessCertificationCaseType.class, query, createCollection(createDistinct()), result);
    AccessCertificationCampaignType campaign1 = getFullCampaign(campaign1Oid, result).asObjectable();
    AccessCertificationCampaignType campaign2 = getFullCampaign(campaign2Oid, result).asObjectable();
    List<AccessCertificationCaseType> expectedCases = new ArrayList<>();
    addUnansweredActiveCases(expectedCases, campaign1.getCase(), campaign1);
    addUnansweredActiveCases(expectedCases, campaign2.getCase(), campaign2);
    PrismAsserts.assertEqualsCollectionUnordered("list of cases is different", cases, expectedCases.toArray(new AccessCertificationCaseType[0]));
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Aggregations

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)31 AccessCertificationCampaignType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)28 AccessCertificationCaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType)27 Task (com.evolveum.midpoint.task.api.Task)22 Test (org.testng.annotations.Test)18 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6 AccessCertificationCampaignStateType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignStateType)5 Date (java.util.Date)5 CertificationHandler (com.evolveum.midpoint.certification.impl.handlers.CertificationHandler)4 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)4 AccessCertificationWorkItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)3 PrismContext (com.evolveum.midpoint.prism.PrismContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 DeltaBuilder (com.evolveum.midpoint.prism.delta.builder.DeltaBuilder)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3