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