Search in sources :

Example 11 with PlainSchemaTO

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

the class BaseUserSelfResource method millisToDate.

protected void millisToDate(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws IllegalArgumentException {
    final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern());
    attrs.stream().filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))).forEachOrdered(attr -> {
        for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext(); ) {
            String value = itor.next();
            try {
                itor.set(fmt.format(Long.valueOf(value)));
            } catch (NumberFormatException ex) {
                LOG.error("Invalid format value for {}", value);
            }
        }
    });
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) ListIterator(java.util.ListIterator) AttrTO(org.apache.syncope.common.lib.to.AttrTO) Set(java.util.Set) IOException(java.io.IOException) ParseException(java.text.ParseException) StandardCharsets(java.nio.charset.StandardCharsets) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat) FastDateFormat(org.apache.commons.lang3.time.FastDateFormat)

Example 12 with PlainSchemaTO

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

the class SchemaDataBinderImpl method getPlainSchemaTO.

@Override
public PlainSchemaTO getPlainSchemaTO(final PlainSchema schema) {
    PlainSchemaTO schemaTO = new PlainSchemaTO();
    BeanUtils.copyProperties(schema, schemaTO, IGNORE_PROPERTIES);
    schemaTO.setAnyTypeClass(schema.getAnyTypeClass() == null ? null : schema.getAnyTypeClass().getKey());
    if (schema.getValidator() != null) {
        schemaTO.setValidator(schema.getValidator().getKey());
    }
    return schemaTO;
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO)

Example 13 with PlainSchemaTO

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

the class SchemaLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_UPDATE + "')")
public <T extends SchemaTO> void update(final SchemaType schemaType, final T schemaTO) {
    if (!doesSchemaExist(schemaType, schemaTO.getKey())) {
        throw new NotFoundException(schemaType + "/" + schemaTO.getKey());
    }
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.find(schemaTO.getKey());
            if (virSchema == null) {
                throw new NotFoundException("Virtual Schema '" + schemaTO.getKey() + "'");
            }
            virSchemaDAO.save(binder.update((VirSchemaTO) schemaTO, virSchema));
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.find(schemaTO.getKey());
            if (derSchema == null) {
                throw new NotFoundException("Derived schema '" + schemaTO.getKey() + "'");
            }
            derSchemaDAO.save(binder.update((DerSchemaTO) schemaTO, derSchema));
            break;
        case PLAIN:
        default:
            PlainSchema plainSchema = plainSchemaDAO.find(schemaTO.getKey());
            if (plainSchema == null) {
                throw new NotFoundException("Schema '" + schemaTO.getKey() + "'");
            }
            plainSchemaDAO.save(binder.update((PlainSchemaTO) schemaTO, plainSchema));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with PlainSchemaTO

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

the class ParametersDetailsPanel method getFieldPanel.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Panel getFieldPanel(final String id, final AttrTO attrTO) {
    final String valueHeaderName = getString("values");
    final PlainSchemaTO schemaTO = schemaRestClient.read(SchemaType.PLAIN, attrTO.getSchema());
    final FieldPanel panel;
    switch(schemaTO.getType()) {
        case Date:
            final String datePattern = schemaTO.getConversionPattern() == null ? SyncopeConstants.DEFAULT_DATE_PATTERN : schemaTO.getConversionPattern();
            if (StringUtils.containsIgnoreCase(datePattern, "H")) {
                panel = new AjaxDateTimeFieldPanel("panel", schemaTO.getKey(), new Model<>(), datePattern);
            } else {
                panel = new AjaxDateFieldPanel("panel", schemaTO.getKey(), new Model<>(), datePattern);
            }
            break;
        case Boolean:
            panel = new AjaxDropDownChoicePanel<>(id, valueHeaderName, new Model<>(), false);
            ((AjaxDropDownChoicePanel<String>) panel).setChoices(Arrays.asList("true", "false"));
            if (!attrTO.getValues().isEmpty()) {
                ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {

                    private static final long serialVersionUID = -3724971416312135885L;

                    @Override
                    public String getDisplayValue(final String value) {
                        return value;
                    }

                    @Override
                    public String getIdValue(final String value, final int i) {
                        return value;
                    }

                    @Override
                    public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
                        return id;
                    }
                });
            }
            ((AjaxDropDownChoicePanel<String>) panel).setNullValid(false);
            break;
        case Enum:
            panel = new AjaxDropDownChoicePanel<>(id, valueHeaderName, new Model<>(), false);
            ((AjaxDropDownChoicePanel<String>) panel).setChoices(SchemaUtils.getEnumeratedValues(schemaTO));
            if (!attrTO.getValues().isEmpty()) {
                ((AjaxDropDownChoicePanel) panel).setChoiceRenderer(new IChoiceRenderer<String>() {

                    private static final long serialVersionUID = -3724971416312135885L;

                    @Override
                    public String getDisplayValue(final String value) {
                        return value;
                    }

                    @Override
                    public String getIdValue(final String value, final int i) {
                        return value;
                    }

                    @Override
                    public String getObject(final String id, final IModel<? extends List<? extends String>> choices) {
                        return id;
                    }
                });
            }
            ((AjaxDropDownChoicePanel<String>) panel).setNullValid("false".equalsIgnoreCase(schemaTO.getMandatoryCondition()));
            break;
        case Long:
            panel = new AjaxSpinnerFieldPanel.Builder<Long>().build(id, valueHeaderName, Long.class, new Model<Long>());
            break;
        case Double:
            panel = new AjaxSpinnerFieldPanel.Builder<Double>().build(id, valueHeaderName, Double.class, new Model<Double>());
            break;
        case Binary:
            panel = new BinaryFieldPanel(id, valueHeaderName, new Model<>(), schemaTO.getMimeType(), schema.getModelObject());
            break;
        case Encrypted:
            panel = new EncryptedFieldPanel(id, valueHeaderName, new Model<>(), true);
            break;
        default:
            panel = new AjaxTextFieldPanel(id, valueHeaderName, new Model<>(), false);
    }
    if (schemaTO.isMultivalue()) {
        return new MultiFieldPanel.Builder<>(new PropertyModel<List<String>>(attrTO, "values")).build(id, valueHeaderName, panel);
    } else {
        panel.setNewModel(attrTO.getValues());
    }
    panel.setRequired("true".equalsIgnoreCase(schemaTO.getMandatoryCondition()));
    return panel;
}
Also used : AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) PropertyModel(org.apache.wicket.model.PropertyModel) AjaxDropDownChoicePanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDropDownChoicePanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) FieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.FieldPanel) AjaxSpinnerFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxSpinnerFieldPanel) EncryptedFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.EncryptedFieldPanel) AjaxTextFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxTextFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel) AjaxDateFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateFieldPanel) MultiFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.MultiFieldPanel) BinaryFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.BinaryFieldPanel) AjaxDateTimeFieldPanel(org.apache.syncope.client.console.wicket.markup.html.form.AjaxDateTimeFieldPanel)

Example 15 with PlainSchemaTO

use of org.apache.syncope.common.lib.to.PlainSchemaTO 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

PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)39 Test (org.junit.jupiter.api.Test)26 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)19 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)11 UserTO (org.apache.syncope.common.lib.to.UserTO)9 AttrTO (org.apache.syncope.common.lib.to.AttrTO)6 Response (javax.ws.rs.core.Response)5 IOException (java.io.IOException)4 Set (java.util.Set)4 StandardCharsets (java.nio.charset.StandardCharsets)3 AnyTypeTO (org.apache.syncope.common.lib.to.AnyTypeTO)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 GroupTO (org.apache.syncope.common.lib.to.GroupTO)3 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)3 SchemaService (org.apache.syncope.common.rest.api.service.SchemaService)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 ListIterator (java.util.ListIterator)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2