Search in sources :

Example 6 with AnyTypeClassTO

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

the class GroupITCase method issueSYNCOPE717.

@Test
public void issueSYNCOPE717() {
    String doubleSchemaName = "double" + getUUIDString();
    // 1. create double schema without conversion pattern
    PlainSchemaTO schema = new PlainSchemaTO();
    schema.setKey(doubleSchemaName);
    schema.setType(AttrSchemaType.Double);
    schema = createSchema(SchemaType.PLAIN, schema);
    assertNotNull(schema);
    assertNull(schema.getConversionPattern());
    AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
    assertNotNull(minimalGroup);
    minimalGroup.getPlainSchemas().add(doubleSchemaName);
    anyTypeClassService.update(minimalGroup);
    // 2. create group, provide valid input value
    GroupTO groupTO = GroupITCase.getBasicSampleTO("syncope717");
    groupTO.getPlainAttrs().add(attrTO(doubleSchemaName, "11.23"));
    groupTO = createGroup(groupTO).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 3. update schema, set conversion pattern
    schema = schemaService.read(SchemaType.PLAIN, schema.getKey());
    schema.setConversionPattern("0.000");
    schemaService.update(SchemaType.PLAIN, schema);
    // 4. re-read group, verify that pattern was applied
    groupTO = groupService.read(groupTO.getKey());
    assertNotNull(groupTO);
    assertEquals("11.230", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 5. modify group with new double value
    GroupPatch patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.257")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.257", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
    // 6. update schema, unset conversion pattern
    schema.setConversionPattern(null);
    schemaService.update(SchemaType.PLAIN, schema);
    // 7. modify group with new double value, verify that no pattern is applied
    patch = new GroupPatch();
    patch.setKey(groupTO.getKey());
    patch.getPlainAttrs().add(new AttrPatch.Builder().attrTO(attrTO(doubleSchemaName, "11.23")).build());
    groupTO = updateGroup(patch).getEntity();
    assertNotNull(groupTO);
    assertEquals("11.23", groupTO.getPlainAttr(doubleSchemaName).get().getValues().get(0));
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Test(org.junit.jupiter.api.Test)

Example 7 with AnyTypeClassTO

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

the class SAML2IdPMappingPanel method setAttrNames.

@Override
protected void setAttrNames(final AjaxTextFieldPanel toBeUpdated) {
    toBeUpdated.setRequired(true);
    toBeUpdated.setEnabled(true);
    List<String> choices = new ArrayList<>(USER_FIELD_NAMES);
    for (AnyTypeClassTO anyTypeClassTO : anyTypeClassRestClient.list(anyTypeRestClient.read(AnyTypeKind.USER.name()).getClasses())) {
        choices.addAll(anyTypeClassTO.getPlainSchemas());
        choices.addAll(anyTypeClassTO.getDerSchemas());
        choices.addAll(anyTypeClassTO.getVirSchemas());
    }
    Collections.sort(choices);
    toBeUpdated.setChoices(choices);
}
Also used : ArrayList(java.util.ArrayList) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO)

Example 8 with AnyTypeClassTO

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

the class AnyTypeClassServiceImpl method create.

@Override
public Response create(final AnyTypeClassTO anyTypeTO) {
    AnyTypeClassTO created = logic.create(anyTypeTO);
    URI location = uriInfo.getAbsolutePathBuilder().path(created.getKey()).build();
    return Response.created(location).header(RESTHeaders.RESOURCE_KEY, created.getKey()).build();
}
Also used : AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) URI(java.net.URI)

Example 9 with AnyTypeClassTO

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

the class AnyTypeClassDataBinderImpl method getAnyTypeClassTO.

@Override
public AnyTypeClassTO getAnyTypeClassTO(final AnyTypeClass anyTypeClass) {
    AnyTypeClassTO anyTypeClassTO = new AnyTypeClassTO();
    anyTypeClassTO.setKey(anyTypeClass.getKey());
    anyTypeClassTO.getInUseByTypes().addAll(anyTypeDAO.findByTypeClass(anyTypeClass).stream().map(Entity::getKey).collect(Collectors.toList()));
    anyTypeClassTO.getPlainSchemas().addAll(anyTypeClass.getPlainSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
    anyTypeClassTO.getDerSchemas().addAll(anyTypeClass.getDerSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
    anyTypeClassTO.getVirSchemas().addAll(anyTypeClass.getVirSchemas().stream().map(Entity::getKey).collect(Collectors.toList()));
    return anyTypeClassTO;
}
Also used : Entity(org.apache.syncope.core.persistence.api.entity.Entity) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO)

Example 10 with AnyTypeClassTO

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

the class AnyTypeClassITCase method crud.

@Test
public void crud() {
    // 1. create sample schemas
    PlainSchemaTO plainSchema = new PlainSchemaTO();
    plainSchema.setKey("new_plain_schema" + getUUIDString());
    plainSchema.setType(AttrSchemaType.String);
    plainSchema = createSchema(SchemaType.PLAIN, plainSchema);
    DerSchemaTO derSchema = new DerSchemaTO();
    derSchema.setKey("new_der_schema" + getUUIDString());
    derSchema.setExpression(plainSchema.getKey() + " + '_' + derived_dx");
    derSchema = createSchema(SchemaType.DERIVED, derSchema);
    // 2. actual CRUD
    AnyTypeClassTO newClass = new AnyTypeClassTO();
    newClass.setKey("new class" + getUUIDString());
    newClass.getPlainSchemas().add(plainSchema.getKey());
    Response response = anyTypeClassService.create(newClass);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
    newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
    assertNotNull(newClass);
    assertFalse(newClass.getPlainSchemas().isEmpty());
    assertTrue(newClass.getDerSchemas().isEmpty());
    assertTrue(newClass.getVirSchemas().isEmpty());
    newClass.getDerSchemas().add(derSchema.getKey());
    anyTypeClassService.update(newClass);
    newClass = anyTypeClassService.read(newClass.getKey());
    assertNotNull(newClass);
    assertFalse(newClass.getPlainSchemas().isEmpty());
    assertFalse(newClass.getDerSchemas().isEmpty());
    assertTrue(newClass.getVirSchemas().isEmpty());
    assertEquals(newClass.getKey(), schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
    assertEquals(newClass.getKey(), schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
    anyTypeClassService.delete(newClass.getKey());
    try {
        anyTypeClassService.read(newClass.getKey());
        fail("This should not happen");
    } catch (SyncopeClientException e) {
        assertEquals(ClientExceptionType.NotFound, e.getType());
    }
    assertNull(schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
    assertNull(schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
}
Also used : Response(javax.ws.rs.core.Response) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) AnyTypeClassService(org.apache.syncope.common.rest.api.service.AnyTypeClassService) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) Test(org.junit.jupiter.api.Test)

Aggregations

AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)28 Test (org.junit.jupiter.api.Test)19 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)12 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)11 UserTO (org.apache.syncope.common.lib.to.UserTO)10 Response (javax.ws.rs.core.Response)8 ResourceTO (org.apache.syncope.common.lib.to.ResourceTO)7 GroupTO (org.apache.syncope.common.lib.to.GroupTO)6 ItemTO (org.apache.syncope.common.lib.to.ItemTO)6 ProvisionTO (org.apache.syncope.common.lib.to.ProvisionTO)6 AnyTypeClassService (org.apache.syncope.common.rest.api.service.AnyTypeClassService)6 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)5 MappingTO (org.apache.syncope.common.lib.to.MappingTO)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 StatusPatch (org.apache.syncope.common.lib.patch.StatusPatch)4 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)4 SchemaType (org.apache.syncope.common.lib.types.SchemaType)4