Search in sources :

Example 11 with AttrTO

use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.

the class DefaultGroupWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<GroupPatch> doUpdate(final Group group, final GroupPatch groupPatch) {
    GroupTO original = dataBinder.getGroupTO(group, true);
    PropagationByResource propByRes = dataBinder.update(group, groupPatch);
    Set<AttrTO> virAttrs = groupPatch.getVirAttrs();
    GroupTO updated = dataBinder.getGroupTO(groupDAO.save(group), true);
    GroupPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(effectivePatch, propByRes, "update");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO)

Example 12 with AttrTO

use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.

the class DefaultUserWorkflowAdapter method doUpdate.

@Override
protected WorkflowResult<Pair<UserPatch, Boolean>> doUpdate(final User user, final UserPatch userPatch) {
    UserTO original = dataBinder.getUserTO(user, true);
    PropagationByResource propByRes = dataBinder.update(user, userPatch);
    PasswordPatch password = userPatch.getPassword();
    Set<AttrTO> virAttrs = userPatch.getVirAttrs();
    UserTO updated = dataBinder.getUserTO(userDAO.save(user), true);
    UserPatch effectivePatch = AnyOperations.diff(updated, original, false);
    effectivePatch.setPassword(password);
    effectivePatch.getVirAttrs().clear();
    effectivePatch.getVirAttrs().addAll(virAttrs);
    return new WorkflowResult<>(Pair.of(effectivePatch, !user.isSuspended()), propByRes, "update");
}
Also used : WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 13 with AttrTO

use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.

the class UserITCase method updateMultivalueAttribute.

@Test
public void updateMultivalueAttribute() {
    UserTO userTO = getUniqueSampleTO("multivalue@syncope.apache.org");
    userTO.getResources().clear();
    userTO.getVirAttrs().clear();
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
    AttrTO loginDate = userTO.getPlainAttr("loginDate").get();
    assertNotNull(loginDate);
    assertEquals(1, loginDate.getValues().size());
    UserPatch userPatch = new UserPatch();
    userPatch.setKey(userTO.getKey());
    loginDate.getValues().add("2000-01-01");
    userPatch.getPlainAttrs().add(new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(loginDate).build());
    userTO = updateUser(userPatch).getEntity();
    assertNotNull(userTO);
    loginDate = userTO.getPlainAttr("loginDate").get();
    assertNotNull(loginDate);
    assertEquals(2, loginDate.getValues().size());
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) Test(org.junit.jupiter.api.Test)

Example 14 with AttrTO

use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.

the class UserITCase method enforceMandatoryCondition.

@Test
public void enforceMandatoryCondition() {
    UserTO userTO = getUniqueSampleTO("enforce@apache.org");
    userTO.getResources().add(RESOURCE_NAME_WS2);
    userTO.setPassword("newPassword12");
    AttrTO type = null;
    for (AttrTO attr : userTO.getPlainAttrs()) {
        if ("ctype".equals(attr.getSchema())) {
            type = attr;
        }
    }
    assertNotNull(type);
    userTO.getPlainAttrs().remove(type);
    try {
        userTO = createUser(userTO).getEntity();
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
    userTO.getPlainAttrs().add(type);
    userTO = createUser(userTO).getEntity();
    assertNotNull(userTO);
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Example 15 with AttrTO

use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.

the class UserITCase method createWithRequiredValueMissing.

@Test
public void createWithRequiredValueMissing() {
    UserTO userTO = getUniqueSampleTO("a.b@c.it");
    AttrTO type = userTO.getPlainAttr("ctype").get();
    userTO.getPlainAttrs().remove(type);
    userTO.getMemberships().add(new MembershipTO.Builder().group("f779c0d4-633b-4be5-8f57-32eb478a3ca5").build());
    // 1. create user without type (mandatory by UserSchema)
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
    userTO.getPlainAttrs().add(attrTO("ctype", "F"));
    AttrTO surname = userTO.getPlainAttr("surname").get();
    userTO.getPlainAttrs().remove(surname);
    // 2. create user without surname (mandatory when type == 'F')
    try {
        createUser(userTO);
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
    }
}
Also used : UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Test(org.junit.jupiter.api.Test)

Aggregations

AttrTO (org.apache.syncope.common.lib.to.AttrTO)70 Test (org.junit.jupiter.api.Test)31 UserTO (org.apache.syncope.common.lib.to.UserTO)30 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)19 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)17 Map (java.util.Map)15 GroupTO (org.apache.syncope.common.lib.to.GroupTO)15 ArrayList (java.util.ArrayList)14 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)14 List (java.util.List)13 Collections (java.util.Collections)11 StringUtils (org.apache.commons.lang3.StringUtils)11 AnyTO (org.apache.syncope.common.lib.to.AnyTO)10 Optional (java.util.Optional)9 Set (java.util.Set)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 HashMap (java.util.HashMap)8 Collectors (java.util.stream.Collectors)8 EntityTOUtils (org.apache.syncope.common.lib.EntityTOUtils)8 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)8