use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.
the class RealmLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
Realm realm = realmDAO.findByFullPath(fullPath);
if (realm == null) {
LOG.error("Could not find realm '" + fullPath + "'");
throw new NotFoundException(fullPath);
}
if (!realmDAO.findChildren(realm).isEmpty()) {
throw SyncopeClientException.build(ClientExceptionType.HasChildren);
}
Set<String> adminRealms = Collections.singleton(realm.getFullPath());
AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
keyCond.setSchema("key");
SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
if (users + groups + anyObjects > 0) {
SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
containedAnys.getElements().add(users + " user(s)");
containedAnys.getElements().add(groups + " group(s)");
containedAnys.getElements().add(anyObjects + " anyObject(s)");
throw containedAnys;
}
PropagationByResource propByRes = new PropagationByResource();
realm.getResourceKeys().forEach(resource -> {
propByRes.add(ResourceOperation.DELETE, resource);
});
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
result.setEntity(binder.getRealmTO(realm, true));
result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
realmDAO.delete(realm);
return result;
}
use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.
the class AbstractAnyLogic method afterCreate.
protected ProvisioningResult<TO> afterCreate(final TO input, final List<PropagationStatus> statuses, final List<LogicActions> actions) {
TO any = input;
for (LogicActions action : actions) {
any = action.afterCreate(any);
}
ProvisioningResult<TO> result = new ProvisioningResult<>();
result.setEntity(any);
result.getPropagationStatuses().addAll(statuses);
return result;
}
use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.
the class JAXBTest method provisioningResult.
@Test
public void provisioningResult() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(ProvisioningResult.class);
Marshaller marshaller = context.createMarshaller();
Unmarshaller unmarshaller = context.createUnmarshaller();
GroupTO group = new GroupTO();
group.setName(UUID.randomUUID().toString());
group.setRealm(SyncopeConstants.ROOT_REALM);
group.getVirAttrs().add(new AttrTO.Builder().schema("rvirtualdata").value("rvirtualvalue").build());
group.getADynMembershipConds().put("USER", "username==a*");
ProvisioningResult<GroupTO> original = new ProvisioningResult<>();
original.setEntity(group);
PropagationStatus status = new PropagationStatus();
status.setFailureReason("failed");
status.setBeforeObj(new ConnObjectTO());
original.getPropagationStatuses().add(status);
StringWriter writer = new StringWriter();
marshaller.marshal(original, writer);
Object actual = unmarshaller.unmarshal(new StringReader(writer.toString()));
assertEquals(original, actual);
}
use of org.apache.syncope.common.lib.to.ProvisioningResult in project syncope by apache.
the class JSONTest method provisioningResult.
@Test
public void provisioningResult() throws IOException {
GroupTO group = new GroupTO();
group.setName(UUID.randomUUID().toString());
group.setRealm(SyncopeConstants.ROOT_REALM);
group.getVirAttrs().add(new AttrTO.Builder().schema("rvirtualdata").value("rvirtualvalue").build());
group.getADynMembershipConds().put("USER", "username==a*");
ProvisioningResult<GroupTO> original = new ProvisioningResult<>();
original.setEntity(group);
PropagationStatus status = new PropagationStatus();
status.setFailureReason("failed");
status.setBeforeObj(new ConnObjectTO());
original.getPropagationStatuses().add(status);
ObjectMapper mapper = new ObjectMapper();
StringWriter writer = new StringWriter();
mapper.writeValue(writer, original);
ProvisioningResult<GroupTO> actual = mapper.readValue(writer.toString(), new TypeReference<ProvisioningResult<GroupTO>>() {
});
assertEquals(original, actual);
}
Aggregations