use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method createAssignmentModification.
protected ContainerDelta<AssignmentType> createAssignmentModification(String roleOid, QName refType, QName relation, Consumer<AssignmentType> modificationBlock, boolean add) throws SchemaException {
ContainerDelta<AssignmentType> assignmentDelta = ContainerDelta.createDelta(UserType.F_ASSIGNMENT, getUserDefinition());
PrismContainerValue<AssignmentType> cval = new PrismContainerValue<AssignmentType>(prismContext);
if (add) {
assignmentDelta.addValueToAdd(cval);
} else {
assignmentDelta.addValueToDelete(cval);
}
PrismReference targetRef = cval.findOrCreateReference(AssignmentType.F_TARGET_REF);
targetRef.getValue().setOid(roleOid);
targetRef.getValue().setTargetType(refType);
targetRef.getValue().setRelation(relation);
if (modificationBlock != null) {
modificationBlock.accept(cval.asContainerable());
}
return assignmentDelta;
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class CertificationCaseHelper method addOrDeleteCases.
protected List<Long> addOrDeleteCases(Session session, String campaignOid, Collection<? extends ItemDelta> modifications) throws SchemaException, DtoTranslationException {
final ItemPath casePath = new ItemPath(AccessCertificationCampaignType.F_CASE);
boolean replacePresent = false;
List<Long> affectedIds = new ArrayList<>();
for (ItemDelta delta : modifications) {
ItemPath deltaPath = delta.getPath();
if (!casePath.isSubPathOrEquivalent(deltaPath)) {
throw new IllegalStateException("Wrong campaign delta sneaked into updateCampaignCases: class=" + delta.getClass() + ", path=" + deltaPath);
}
if (deltaPath.size() == 1) {
if (delta.getValuesToDelete() != null) {
// todo do 'bulk' delete like delete from ... where oid=? and id in (...)
for (PrismContainerValue value : (Collection<PrismContainerValue>) delta.getValuesToDelete()) {
Long id = value.getId();
if (id == null) {
throw new SchemaException("Couldn't delete certification case with null id");
}
affectedIds.add(id);
// TODO couldn't this cascading be done by hibernate itself?
Integer integerCaseId = RUtil.toInteger(id);
// Query deleteCaseReferences = session.createSQLQuery("delete from " + RCertCaseReference.TABLE +
// " where owner_owner_oid=:oid and owner_id=:id");
// deleteCaseReferences.setString("oid", campaignOid);
// deleteCaseReferences.setInteger("id", integerCaseId);
// deleteCaseReferences.executeUpdate();
Query deleteWorkItemReferences = session.createSQLQuery("delete from " + RCertWorkItemReference.TABLE + " where owner_owner_owner_oid=:oid and owner_owner_id=:id");
deleteWorkItemReferences.setString("oid", campaignOid);
deleteWorkItemReferences.setInteger("id", integerCaseId);
deleteWorkItemReferences.executeUpdate();
Query deleteCaseWorkItems = session.createSQLQuery("delete from " + RAccessCertificationWorkItem.TABLE + " where owner_owner_oid=:oid and owner_id=:id");
deleteCaseWorkItems.setString("oid", campaignOid);
deleteCaseWorkItems.setInteger("id", integerCaseId);
deleteCaseWorkItems.executeUpdate();
Query deleteCase = session.getNamedQuery("delete.campaignCase");
deleteCase.setString("oid", campaignOid);
deleteCase.setInteger("id", integerCaseId);
deleteCase.executeUpdate();
}
}
// So it's safest not to provide any IDs by the client
if (delta.getValuesToAdd() != null) {
int currentId = generalHelper.findLastIdInRepo(session, campaignOid, "get.campaignCaseLastId") + 1;
addCertificationCampaignCases(session, campaignOid, delta.getValuesToAdd(), currentId, affectedIds);
}
if (delta.getValuesToReplace() != null) {
deleteCertificationCampaignCases(session, campaignOid);
addCertificationCampaignCases(session, campaignOid, delta.getValuesToReplace(), 1, affectedIds);
replacePresent = true;
}
}
}
return replacePresent ? null : affectedIds;
}
use of com.evolveum.midpoint.prism.PrismContainerValue 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.prism.PrismContainerValue in project midpoint by Evolveum.
the class LookupTableHelper method addLookupTableRows.
private void addLookupTableRows(Session session, String tableOid, Collection<PrismContainerValue> values, int currentId, boolean deleteBeforeAdd) throws SchemaException {
for (PrismContainerValue value : values) {
LookupTableRowType rowType = new LookupTableRowType();
rowType.setupContainerValue(value);
if (deleteBeforeAdd) {
deleteRowByKey(session, tableOid, rowType.getKey());
}
RLookupTableRow row = RLookupTableRow.toRepo(tableOid, rowType);
row.setId(currentId);
currentId++;
session.save(row);
}
}
use of com.evolveum.midpoint.prism.PrismContainerValue in project midpoint by Evolveum.
the class AddAssignmentAspect method assignmentToDelta.
// creates an ObjectDelta that will be executed after successful approval of the given assignment
@SuppressWarnings("unchecked")
private ObjectDelta<? extends FocusType> assignmentToDelta(ModelContext<?> modelContext, AssignmentType assignmentType, String objectOid) {
PrismObject<FocusType> focus = (PrismObject<FocusType>) modelContext.getFocusContext().getObjectNew();
PrismContainerDefinition<AssignmentType> prismContainerDefinition = focus.getDefinition().findContainerDefinition(FocusType.F_ASSIGNMENT);
ItemDelta<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> addRoleDelta = new ContainerDelta<>(new ItemPath(), FocusType.F_ASSIGNMENT, prismContainerDefinition, prismContext);
PrismContainerValue<AssignmentType> assignmentValue = assignmentType.asPrismContainerValue().clone();
addRoleDelta.addValueToAdd(assignmentValue);
Class focusClass = primaryChangeAspectHelper.getFocusClass(modelContext);
return ObjectDelta.createModifyDelta(objectOid, addRoleDelta, focusClass, modelContext.getPrismContext());
}
Aggregations