Search in sources :

Example 16 with ObjectDelta

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) ConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 17 with ObjectDelta

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;
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 18 with ObjectDelta

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();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Iterator(java.util.Iterator) MyPasswordQuestionsPanel(com.evolveum.midpoint.web.page.admin.home.component.MyPasswordQuestionsPanel) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 19 with ObjectDelta

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());
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(java.io.File) Test(org.testng.annotations.Test)

Example 20 with ObjectDelta

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);
}
Also used : ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26