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;
}
}
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);
}
}
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();
}
}
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, "");
}
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;
}
}
Aggregations