use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class ConfigurationITCase method delete.
@Test
public void delete() throws UnsupportedEncodingException {
try {
configurationService.delete("nonExistent");
fail("The delete operation should throw an exception because of nonExistent schema");
} catch (SyncopeClientException e) {
assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
}
AttrTO tokenLength = configurationService.get("token.length");
configurationService.delete("token.length");
AttrTO actual = configurationService.get(tokenLength.getSchema());
assertNotEquals(actual, tokenLength);
configurationService.set(tokenLength);
actual = configurationService.get(tokenLength.getSchema());
assertEquals(actual, tokenLength);
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class ConfigurationITCase method update.
@Test
public void update() {
AttrTO expireTime = configurationService.get("token.expireTime");
int value = Integer.parseInt(expireTime.getValues().get(0));
value++;
expireTime.getValues().set(0, value + "");
configurationService.set(expireTime);
AttrTO newConfigurationTO = configurationService.get(expireTime.getSchema());
assertEquals(expireTime, newConfigurationTO);
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class ConfigurationITCase method createRequired.
@Test
public void createRequired() {
PlainSchemaTO testKey = new PlainSchemaTO();
testKey.setKey("testKey" + getUUIDString());
testKey.setType(AttrSchemaType.String);
testKey.setMandatoryCondition("true");
createSchema(SchemaType.PLAIN, testKey);
AttrTO conf = new AttrTO.Builder().schema(testKey.getKey()).build();
try {
configurationService.set(conf);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
}
conf.getValues().add("testValue");
configurationService.set(conf);
AttrTO actual = configurationService.get(conf.getSchema());
actual.setSchemaInfo(null);
assertEquals(actual, conf);
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class DefaultGroupProvisioningManager method create.
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public Pair<String, List<PropagationStatus>> create(final GroupTO groupTO, final Map<String, String> groupOwnerMap, final Set<String> excludedResources, final boolean nullPriorityAsync) {
WorkflowResult<String> created = gwfAdapter.create(groupTO);
// see ConnObjectUtils#getAnyTOFromConnObject for GroupOwnerSchema
Optional<AttrTO> groupOwner = groupTO.getPlainAttr(StringUtils.EMPTY);
if (groupOwner.isPresent()) {
groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
}
List<PropagationTaskTO> tasks = propagationManager.getCreateTasks(AnyTypeKind.GROUP, created.getResult(), created.getPropByRes(), groupTO.getVirAttrs(), excludedResources);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, nullPriorityAsync);
return Pair.of(created.getResult(), propagationReporter.getStatuses());
}
use of org.apache.syncope.common.lib.to.AttrTO in project syncope by apache.
the class AbstractAnyDataBinder method fill.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
// 0. aux classes
any.getAuxClasses().clear();
anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
if (auxClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
} else {
any.add(auxClass);
}
});
// 1. attributes
SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
PlainSchema schema = getPlainSchema(attrTO.getSchema());
if (schema != null) {
PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
if (attr == null) {
attr = anyUtils.newPlainAttr();
((PlainAttr) attr).setOwner(any);
attr.setSchema(schema);
}
fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
if (attr.getValuesAsStrings().isEmpty()) {
attr.setOwner(null);
} else {
any.add(attr);
}
}
});
if (!invalidValues.isEmpty()) {
scce.addException(invalidValues);
}
SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
// 2. resources
anyTO.getResources().forEach(resourceKey -> {
ExternalResource resource = resourceDAO.find(resourceKey);
if (resource == null) {
LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
} else {
any.add(resource);
}
});
requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
if (!requiredValuesMissing.isEmpty()) {
scce.addException(requiredValuesMissing);
}
}
Aggregations