getByPath method added

master
lucio 4 years ago
parent fae5173b17
commit 774e2b4bfb

@ -12,7 +12,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.data.access</groupId>
<artifactId>storagehub</artifactId>
<version>1.0.9</version>
<version>1.1.0</version>
<name>storagehub</name>
<scm>

@ -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)

@ -25,7 +25,7 @@ The projects leading to this software have received funding from a series of
Version
--------------------------------------------------
1.0.9 (2020-01-24)
1.1.0 (2020-03-03)
Please see the file named "changelog.xml" in this directory for the release notes.

@ -1,7 +1,7 @@
<application mode='online'>
<name>StorageHub</name>
<group>DataAccess</group>
<version>1.0.9</version>
<version>1.1.0</version>
<description>Storage Hub webapp</description>
<local-persistence location='target' />
</application>
Loading…
Cancel
Save