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