use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class AssignExecutor method createDelta.
private ObjectDelta createDelta(ObjectType objectType, Collection<ObjectReferenceType> resources, Collection<ObjectReferenceType> roles) throws ScriptExecutionException {
List<AssignmentType> assignments = new ArrayList<>();
if (roles != null) {
for (ObjectReferenceType roleRef : roles) {
AssignmentType assignmentType = new AssignmentType();
assignmentType.setTargetRef(roleRef);
assignments.add(assignmentType);
}
}
if (resources != null) {
for (ObjectReferenceType resourceRef : resources) {
AssignmentType assignmentType = new AssignmentType();
ConstructionType constructionType = new ConstructionType();
constructionType.setResourceRef(resourceRef);
assignmentType.setConstruction(constructionType);
assignments.add(assignmentType);
}
}
ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(objectType.getClass(), objectType.getOid(), prismContext);
try {
delta.addModificationAddContainer(FocusType.F_ASSIGNMENT, assignments.toArray(new AssignmentType[0]));
} catch (SchemaException e) {
throw new ScriptExecutionException("Couldn't prepare modification to add resource/role assignments", e);
}
return delta;
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class PurgeSchemaExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue<Objectable>) value).asObjectable() instanceof ResourceType) {
PrismObject<ResourceType> resourceTypePrismObject = ((PrismObjectValue) value).asPrismObject();
ResourceType resourceType = resourceTypePrismObject.asObjectable();
long started = operationsHelper.recordStart(context, resourceType);
ObjectDelta delta = createDelta(resourceTypePrismObject.asObjectable());
try {
if (delta != null) {
operationsHelper.applyDelta(delta, ModelExecuteOptions.createRaw(), context, result);
context.println("Purged schema information from " + resourceTypePrismObject);
output.addValue(operationsHelper.getObject(ResourceType.class, resourceTypePrismObject.getOid(), true, context, result).getValue(), item.getResult());
} else {
context.println("There's no schema information to be purged in " + value);
output.addValue(resourceTypePrismObject.getValue(), item.getResult());
}
operationsHelper.recordEnd(context, resourceType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, resourceType, started, ex);
Throwable exception = processActionException(ex, NAME, value, context);
context.println("Couldn't purge schema information from " + resourceTypePrismObject + exceptionSuffix(exception));
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject<ResourceType>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return output;
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class PageMyPasswordQuestions method updateQuestions.
private void updateQuestions(String useroid, AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_SAVE_QUESTIONS);
OperationResult result = new OperationResult(OPERATION_SAVE_QUESTIONS);
SchemaRegistry registry = getPrismContext().getSchemaRegistry();
SecurityQuestionAnswerType[] answerTypeList = new SecurityQuestionAnswerType[questionNumber];
try {
int listnum = 0;
for (Iterator iterator = pqPanels.iterator(); iterator.hasNext(); ) {
MyPasswordQuestionsPanel type = (MyPasswordQuestionsPanel) iterator.next();
SecurityQuestionAnswerType answerType = new SecurityQuestionAnswerType();
ProtectedStringType answer = new ProtectedStringType();
answer.setClearValue(((TextField<String>) type.get(MyPasswordQuestionsPanel.F_ANSWER)).getModelObject());
answerType.setQuestionAnswer(answer);
//used apache's unescapeHtml method for special chars like \'
String results = StringEscapeUtils.unescapeHtml((type.get(MyPasswordQuestionsPanel.F_QUESTION)).getDefaultModelObjectAsString());
answerType.setQuestionIdentifier(getQuestionIdentifierFromQuestion(results));
answerTypeList[listnum] = answerType;
listnum++;
}
//if(answerTypeList.length !=)
// fill in answerType data here
ItemPath path = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
ObjectDelta<UserType> objectDelta = ObjectDelta.createModificationReplaceContainer(UserType.class, useroid, path, getPrismContext(), answerTypeList);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
getModelService().executeChanges(deltas, null, task, result);
/*
System.out.println("getModel");
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
PasswordQuestionsDto dto = new PasswordQuestionsDto();
PrismObjectDefinition objDef =registry.findObjectDefinitionByCompileTimeClass(UserType.class);
Class<? extends ObjectType> type = UserType.class;
final ItemPath valuePath = new ItemPath(SchemaConstantsGenerated.C_CREDENTIALS,
CredentialsType.F_SECURITY_QUESTIONS, SecurityQuestionsCredentialsType.F_QUESTION_ANSWER);
SecurityQuestionAnswerType secQuesAnsType= new SecurityQuestionAnswerType();
ProtectedStringType protStrType= new ProtectedStringType();
protStrType.setClearValue("deneme");
secQuesAnsType.setQuestionAnswer(protStrType);
dto.setSecurityAnswers(new ArrayList<SecurityQuestionAnswerType>());
dto.getSecurityAnswers().add(secQuesAnsType);
PropertyDelta delta = PropertyDelta.createModificationReplaceProperty(valuePath, objDef, dto.getSecurityAnswers().get(0).getQuestionAnswer());
// PropertyDelta delta= PropertyDelta.createModifica
System.out.println("Update Questions3");
deltas.add(ObjectDelta.createModifyDelta(useroid, delta, type, getPrismContext()));
System.out.println("Update Questions4");
getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_QUESTIONS), result);
System.out.println("Update Questions5");
*/
success(getString("message.success"));
target.add(getFeedbackPanel());
} catch (Exception ex) {
error(getString("message.error"));
target.add(getFeedbackPanel());
ex.printStackTrace();
}
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestParseDiffPatch method testCampaign.
// private void assertXmlMod(ObjectModificationType objectModificationType, QName propertyName,
// ModificationTypeType modType, String... expectedValues) {
// for (ItemDeltaType mod: objectModificationType.getItemDelta()) {
// assertEquals(modType, mod.getModificationType());
// for (RawType val : mod.getValue()){
// List<Object> elements = val.getContent();
// assertFalse(elements.isEmpty());
// Object first = elements.get(0);
//// QName elementQName = JAXBUtil.getElementQName(first);
// if (propertyName.equals(mod.getPath().getItemPath().last())) {
//
// assertEquals(expectedValues.length, elements.size());
// for (Object element: elements) {
// boolean found = false;
// for (String expectedValue: expectedValues) {
// Element domElement = (Element)element;
// if (expectedValue.equals(domElement.getTextContent())) {
// found = true;
// }
// }
// assertTrue(found);
// }
// }
// }
// }
// }
// this is a simple test of applying delta (don't know where to put it)
// MID-3828
@Test
public void testCampaign() throws SchemaException, SAXException, IOException, JAXBException {
System.out.println("===[ testCampaign ]===");
PrismObject<AccessCertificationCampaignType> campaign = PrismTestUtil.parseObject(new File(TEST_DIR, "campaign-1.xml"));
campaign.checkConsistence();
assertEquals("Wrong # of triggers", 2, campaign.asObjectable().getTrigger().size());
// WHEN
TriggerType triggerToDelete = new TriggerType(getPrismContext());
// non-existing ID
triggerToDelete.setId(3L);
triggerToDelete.setTimestamp(XmlTypeConverter.createXMLGregorianCalendar("2017-03-17T23:43:49.705+01:00"));
triggerToDelete.setHandlerUri("http://midpoint.evolveum.com/xml/ns/public/certification/trigger/close-stage/handler-3");
@SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<AccessCertificationCampaignType> delta = (ObjectDelta<AccessCertificationCampaignType>) DeltaBuilder.deltaFor(AccessCertificationCampaignType.class, getPrismContext()).item(AccessCertificationCampaignType.F_TRIGGER).delete(triggerToDelete).asObjectDelta(campaign.getOid());
// THEN
delta.applyTo(campaign);
System.out.println("Campaign after:\n" + campaign.debugDump());
assertEquals("Wrong # of triggers", 2, campaign.asObjectable().getTrigger().size());
}
use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.
the class TestDeltaConverter method test110ObjectModifyNone.
@Test
public void test110ObjectModifyNone() throws Exception {
System.out.println("===[ test110ObjectModifyNone ]====");
ObjectDelta delta = DeltaBuilder.deltaFor(UserType.class, getPrismContext()).asObjectDelta("123456");
roundTrip(delta);
}
Aggregations