Skip to content

Commit

Permalink
Fixing exception vs null in scripting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 22, 2014
1 parent 3c96da7 commit a130090
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Expand Up @@ -869,11 +869,11 @@ <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query)
// however, the syntax of orgType attribute is not standardized
Collection<String> getOrgUnits(UserType user);

OrgType getOrgByOid(String oid) throws ObjectNotFoundException, SchemaException;
OrgType getOrgByOid(String oid) throws SchemaException;

OrgType getOrgByName(String name) throws ObjectNotFoundException, SchemaException;
OrgType getOrgByName(String name) throws SchemaException;

OrgType getParentOrgByOrgType(ObjectType object, String orgType) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException;
OrgType getParentOrgByOrgType(ObjectType object, String orgType) throws SchemaException, SecurityViolationException, CommunicationException, ConfigurationException;

Collection<UserType> getManagersOfOrg(String orgOid) throws SchemaException;

Expand Down
Expand Up @@ -184,17 +184,21 @@ public Collection<String> getOrgUnits(UserType user) {
}

@Override
public OrgType getOrgByOid(String oid) throws ObjectNotFoundException, SchemaException {
return repositoryService.getObject(OrgType.class, oid, null, new OperationResult("getOrgByOid")).asObjectable();
public OrgType getOrgByOid(String oid) throws SchemaException {
try {
return repositoryService.getObject(OrgType.class, oid, null, new OperationResult("getOrgByOid")).asObjectable();
} catch (ObjectNotFoundException e) {
return null;
}
}

@Override
public OrgType getOrgByName(String name) throws ObjectNotFoundException, SchemaException {
public OrgType getOrgByName(String name) throws SchemaException {
PolyString polyName = new PolyString(name);
ObjectQuery q = ObjectQueryUtil.createNameQuery(polyName, prismContext);
List<PrismObject<OrgType>> result = repositoryService.searchObjects(OrgType.class, q, null, new OperationResult("getOrgByName"));
if (result.isEmpty()) {
throw new ObjectNotFoundException("No organizational unit with the name '" + name + "'", name);
return null;
}
if (result.size() > 1) {
throw new IllegalStateException("More than one organizational unit with the name '" + name + "' (there are " + result.size() + " of them)");
Expand All @@ -203,10 +207,15 @@ public OrgType getOrgByName(String name) throws ObjectNotFoundException, SchemaE
}

@Override
public OrgType getParentOrgByOrgType(ObjectType object, String orgType) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException {
public OrgType getParentOrgByOrgType(ObjectType object, String orgType) throws SchemaException, SecurityViolationException, CommunicationException, ConfigurationException {
List<ObjectReferenceType> parentOrgRefs = object.getParentOrgRef();
for (ObjectReferenceType parentOrgRef: parentOrgRefs) {
OrgType parentOrg = getObject(OrgType.class, parentOrgRef.getOid());
OrgType parentOrg;
try {
parentOrg = getObject(OrgType.class, parentOrgRef.getOid());
} catch (ObjectNotFoundException e) {
return null;
}
if (orgType == null || parentOrg.getOrgType().contains(orgType)) {
return parentOrg;
}
Expand Down

0 comments on commit a130090

Please sign in to comment.