Search in sources :

Example 21 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class PageRegistrationConfirmation method assignDefaultRoles.

private void assignDefaultRoles(String userOid, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
    List<ObjectReferenceType> rolesToAssign = getSelfRegistrationConfiguration().getDefaultRoles();
    if (CollectionUtils.isEmpty(rolesToAssign)) {
        return;
    }
    OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_DEFAULT_ROLES);
    try {
        PrismContext prismContext = getPrismContext();
        List<AssignmentType> assignmentsToCreate = rolesToAssign.stream().map(ref -> ObjectTypeUtil.createAssignmentTo(ref, prismContext)).collect(Collectors.toList());
        ObjectDelta<Objectable> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).addRealValues(assignmentsToCreate).asObjectDelta(userOid);
        runAsChecked(() -> {
            Task task = createSimpleTask(OPERATION_ASSIGN_DEFAULT_ROLES);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
            return null;
        }, administrator);
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageRegistrationConfirmation.message.assignDefaultRoles.fatalError"), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) PageDescriptor(com.evolveum.midpoint.authentication.api.authorization.PageDescriptor) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AuthenticationException(org.springframework.security.core.AuthenticationException) StringValue(org.apache.wicket.util.string.StringValue) Label(org.apache.wicket.markup.html.basic.Label) Url(com.evolveum.midpoint.authentication.api.authorization.Url) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Objectable(com.evolveum.midpoint.prism.Objectable) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) CommonException(com.evolveum.midpoint.util.exception.CommonException) List(java.util.List) Validate(org.apache.commons.lang3.Validate) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) NonceAuthenticationContext(com.evolveum.midpoint.model.api.context.NonceAuthenticationContext) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Objectable(com.evolveum.midpoint.prism.Objectable) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 22 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class SearchShadowOwnerTest method initSystem.

@Override
public void initSystem() throws Exception {
    super.initSystem();
    OperationResult result = new OperationResult("Add sample data");
    // insert sample data
    final File OBJECTS_FILE = new File(FOLDER_BASIC, "objects.xml");
    List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(OBJECTS_FILE).parseObjects();
    for (int i = 0; i < elements.size(); i++) {
        PrismObject object = elements.get(i);
        repositoryService.addObject(object, null, result);
    }
    result.computeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File)

Example 23 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class TestTextFormatter method test050FormatDeltaWithOperAndAuxItems.

@Test
public void test050FormatDeltaWithOperAndAuxItems() throws Exception {
    given();
    PrismObject<UserType> jack = PrismTestUtil.parseObject(new File(USER_JACK_FILE));
    displayValue("jack", jack.debugDump());
    // @formatter:off
    ObjectDelta<Objectable> delta = prismContext.deltaFor(UserType.class).item(UserType.F_LINK_REF).add(ObjectTypeUtil.createObjectRef("aecfb587-cc61-41aa-aeeb-962d4369de86", ObjectTypes.SHADOW)).item(UserType.F_METADATA, MetadataType.F_MODIFY_TIMESTAMP).replace(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis())).asObjectDelta("some-user-oid");
    // @formatter:on
    displayValue("delta", delta.debugDump());
    when();
    String deltaFormattedHideNone = textFormatter.formatObjectModificationDelta(delta, null, true, jack, null);
    System.out.println("no hidden paths + show operational attributes:\n" + deltaFormattedHideNone);
    String deltaFormattedHideOper = textFormatter.formatObjectModificationDelta(delta, null, false, jack, null);
    System.out.println("no hidden paths + hide operational attributes:\n" + deltaFormattedHideOper);
    String deltaFormattedHideAux = textFormatter.formatObjectModificationDelta(delta, auxiliaryPaths, true, jack, null);
    System.out.println("hide auxiliary paths + show operational attributes:\n" + deltaFormattedHideAux);
    String deltaFormattedHideAuxAndOper = textFormatter.formatObjectModificationDelta(delta, auxiliaryPaths, false, jack, null);
    System.out.println("hide auxiliary paths + hide operational attributes:\n" + deltaFormattedHideAuxAndOper);
    then();
// TODO create some asserts here
}
Also used : Objectable(com.evolveum.midpoint.prism.Objectable) File(java.io.File) Test(org.testng.annotations.Test) AbstractSpringTest(com.evolveum.midpoint.test.util.AbstractSpringTest)

Example 24 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class TestXmlJsonRoundtrip method doubleSerialization.

@NotNull
private PrismObject<Objectable> doubleSerialization(File name) throws SchemaException, IOException {
    PrismContext context = getPrismContext();
    PrismObject<Objectable> xmlObject = context.parserFor(name).language("xml").parse();
    assertNotNull(xmlObject);
    String jsonString = context.jsonSerializer().serialize(xmlObject);
    display(jsonString);
    @NotNull PrismObject<Objectable> jsonObject = context.parserFor(jsonString).language("json").parse();
    assertObjectEquals(jsonObject, xmlObject);
    String json2String = context.jsonSerializer().serialize(jsonObject);
    var json2Object = context.parserFor(json2String).language("json").parse();
    assertObjectEquals(jsonObject, json2Object);
    return json2Object;
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) Objectable(com.evolveum.midpoint.prism.Objectable) Assert.assertNotNull(org.testng.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull) Assert.assertNotNull(org.testng.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with Objectable

use of com.evolveum.midpoint.prism.Objectable in project midpoint by Evolveum.

the class DeleteTest method test100DeleteObjects.

@Test
public void test100DeleteObjects() throws Exception {
    List<PrismObject<? extends Objectable>> objects = prismContext.parserFor(new File(FOLDER_BASIC, "objects.xml")).parseObjects();
    OperationResult result = new OperationResult("add objects");
    List<String> oids = new ArrayList<>();
    for (PrismObject object : objects) {
        oids.add(repositoryService.addObject(object, null, result));
    }
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
    for (int i = 0; i < objects.size(); i++) {
        repositoryService.deleteObject((Class) objects.get(i).getCompileTimeClass(), oids.get(i), result);
    }
    result.recomputeStatus();
    AssertJUnit.assertTrue(result.isSuccess());
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Objectable (com.evolveum.midpoint.prism.Objectable)26 PrismObject (com.evolveum.midpoint.prism.PrismObject)17 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 File (java.io.File)9 Test (org.testng.annotations.Test)9 PrismContext (com.evolveum.midpoint.prism.PrismContext)6 Node (org.w3c.dom.Node)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 Task (com.evolveum.midpoint.task.api.Task)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 EventHandler (com.evolveum.midpoint.common.validator.EventHandler)3 Validator (com.evolveum.midpoint.common.validator.Validator)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 Element (org.w3c.dom.Element)3 PageDescriptor (com.evolveum.midpoint.authentication.api.authorization.PageDescriptor)2 Url (com.evolveum.midpoint.authentication.api.authorization.Url)2 WebModelServiceUtils (com.evolveum.midpoint.gui.api.util.WebModelServiceUtils)2 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)2