public ConnObjectTO getConnectorObject(@PathVariable("resourceName") final String resourceName,
@PathVariable("type") final AttributableType type, @PathVariable("id") final Long id) {
ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
throw new NotFoundException("Resource '" + resourceName + "'");
}
AbstractAttributable attributable = null;
switch (type) {
case USER:
attributable = userDAO.find(id);
break;
case ROLE:
attributable = roleDAO.find(id);
break;
case MEMBERSHIP:
default:
throw new IllegalArgumentException("Not supported for MEMBERSHIP");
}
if (attributable == null) {
throw new NotFoundException(type + " '" + id + "'");
}
final AttributableUtil attrUtil = AttributableUtil.getInstance(type);
final String accountIdValue =
MappingUtil.getAccountIdValue(attributable, resource, attrUtil.getAccountIdItem(resource));
final ObjectClass objectClass = AttributableType.USER == type ? ObjectClass.ACCOUNT : ObjectClass.GROUP;
final Connector connector = connFactory.getConnector(resource);
final ConnectorObject connectorObject = connector.getObject(objectClass, new Uid(accountIdValue),
connector.getOperationOptions(attrUtil.getMappingItems(resource, MappingPurpose.BOTH)));
if (connectorObject == null) {
throw new NotFoundException("Object " + accountIdValue + " with class " + objectClass
+ "not found on resource " + resourceName);
}
final Set<Attribute> attributes = connectorObject.getAttributes();
if (AttributeUtil.find(Uid.NAME, attributes) == null) {