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);
}
}
});
}
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;
}
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));
}
}
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;
}
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());
}
Aggregations