|
|
|
@ -148,7 +148,65 @@ public class ItemsManager {
|
|
|
|
|
|
|
|
|
|
return new ItemWrapper<Item>(toReturn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/path")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public ItemWrapper<Item> getByRelativePath(@QueryParam("path") String path, @QueryParam("exclude") List<String> excludes){
|
|
|
|
|
InnerMethodName.instance.set("getByPath");
|
|
|
|
|
Session ses = null;
|
|
|
|
|
Item toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, id);
|
|
|
|
|
|
|
|
|
|
String relativePath = path.startsWith("/")? path.substring(1) : path;
|
|
|
|
|
if (path.endsWith("/"))
|
|
|
|
|
relativePath.substring(0,relativePath.lastIndexOf("/"));
|
|
|
|
|
|
|
|
|
|
if (relativePath.isEmpty()) throw new InvalidCallParameters("empty path");
|
|
|
|
|
|
|
|
|
|
Item item =null;
|
|
|
|
|
String nextId = id;
|
|
|
|
|
String[] paths = relativePath.split("/");
|
|
|
|
|
for (String actualPath: paths) {
|
|
|
|
|
item = getChildrenMatchingName(ses, nextId, actualPath, excludes);
|
|
|
|
|
if (item ==null) throw new InvalidCallParameters("relative path "+actualPath+" not found under item with id "+nextId);
|
|
|
|
|
authChecker.checkReadAuthorizationControl(ses, item.getId());
|
|
|
|
|
nextId = item.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new ItemWrapper<Item>(item);
|
|
|
|
|
}catch(RepositoryException re){
|
|
|
|
|
log.error("jcr error getting item", re);
|
|
|
|
|
GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error searching item", re));
|
|
|
|
|
}catch(StorageHubException she ){
|
|
|
|
|
log.error(she.getErrorMessage(), she);
|
|
|
|
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
|
|
|
|
}finally{
|
|
|
|
|
if (ses!=null)
|
|
|
|
|
ses.logout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new ItemWrapper<Item>(toReturn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Item getChildrenMatchingName(Session ses, String id, String name, List<String> excludes) throws ItemNotFoundException , RepositoryException, StorageHubException {
|
|
|
|
|
|
|
|
|
|
NodeIterator it = ses.getNodeByIdentifier(id).getNodes();
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
Node child= it.nextNode();
|
|
|
|
|
String nodeName = child.getName();
|
|
|
|
|
if (!child.hasProperty(NodeProperty.TITLE.toString())) continue;
|
|
|
|
|
String title = child.getProperty(NodeProperty.TITLE.toString()).getString();
|
|
|
|
|
|
|
|
|
|
if (nodeName.equals(name) || title.equals(name)){
|
|
|
|
|
return node2Item.getItem(child, excludes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("{id}/items/{name}")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|