setHidden for items added

search with excludeHidden added
This commit is contained in:
lucio 2020-03-16 16:58:12 +01:00
parent f8cce90467
commit 6e8600bbf3
5 changed files with 73 additions and 10 deletions

View File

@ -115,7 +115,6 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<target>1.8</target>
<source>1.8</source>

View File

@ -190,6 +190,18 @@ public class FolderContainer extends ItemContainer<FolderItem>{
return new OpenResolver(itemclient.getByRelativePath(id, relativePath), itemclient);
}
/**
*
* returns the items that matches the name pattern searching recursively on all subfolders filtering the trashed Items
*
* @return {@ListResolver}
* @throws {@InvalidItemException}
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
*/
public ListResolver search(String nameTomatch, boolean excludeTrashed) throws StorageHubException {
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.search(itemId, onlyType, includeHidden, excludeTrashed, nameTomatch, excludes), itemclient);
}
/**
*
* returns the items that matches the name pattern searching recursively on all subfolders
@ -199,7 +211,7 @@ public class FolderContainer extends ItemContainer<FolderItem>{
* @throws {@UserNotAuthorizedException} if user is not authorized to read this folder
*/
public ListResolver search(String nameTomatch) throws StorageHubException {
return new ListResolver((onlyType, includeHidden, excludes) -> itemclient.search(itemId, onlyType, includeHidden, nameTomatch, excludes), itemclient);
return search(nameTomatch, true);
}
/**

View File

@ -2,6 +2,7 @@ package org.gcube.common.storagehub.client.proxies;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -197,7 +198,7 @@ public class DefaultItemManager implements ItemManagerClient {
return getChildren(id, null, showHidden, excludeNodes);
}
public List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean showHidden, String nameToMatch, String ... excludeNodes) throws StorageHubException{
public List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean showHidden, boolean excludeTrashed, String nameToMatch, String ... excludeNodes) throws StorageHubException{
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
@Override
public ItemList call(GXWebTargetAdapterRequest manager) throws StorageHubException, Exception {
@ -210,8 +211,9 @@ public class DefaultItemManager implements ItemManagerClient {
if (onlyOfType!=null)
params.put("onlyType", new Object[] {resolveNodeType(onlyOfType)});
params.put("showHidden", new Object[] {showHidden});
params.put("name", new Object[] {nameToMatch});
params.put("name", new String[] {URLEncoder.encode( nameToMatch, "UTF-8" )});
params.put("excludeTrashed", new Object[] {excludeTrashed});
GXInboundResponse response = myManager.queryParams(params).get();
if (response.isErrorResponse()) {
@ -1272,6 +1274,42 @@ public class DefaultItemManager implements ItemManagerClient {
}
}
@Override
public String setHidden(String id, Boolean value) throws StorageHubException {
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
@Override
public String call(GXWebTargetAdapterRequest manager) throws Exception {
Objects.requireNonNull(id, "id cannot be null");
Objects.requireNonNull(value, "value cannot be null");
GXWebTargetAdapterRequest myManager = manager.path(id)
.path("hidden");
GXInboundResponse response = myManager.put(Entity.json(value));
if (response.isErrorResponse()) {
if (response.hasException())
throw response.getException();
else
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
}
return response.getSource().readEntity(String.class);
}
};
try {
return delegate.make(call);
}catch(StorageHubException e) {
throw e;
}catch(Exception e1) {
throw new RuntimeException(e1);
}
}
@Override
public String setMetadata(String id, Metadata metadata) throws StorageHubException {

View File

@ -28,7 +28,7 @@ public interface ItemManagerClient {
List<? extends Item> getAnchestors(String id, String ... excludeNodes) throws StorageHubException;
List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean includeHidden, String nameToMatch, String ... excludeNodes) throws StorageHubException;
List<? extends Item> search(String id, Class<? extends Item> onlyOfType, boolean includeHidden, boolean excludeTrashed, String nameToMatch, String ... excludeNodes) throws StorageHubException;
Integer childrenCount(String id,boolean includeHidden) throws StorageHubException ;
@ -83,6 +83,8 @@ public interface ItemManagerClient {
StreamDescriptor downloadSpecificVersion(String id, String version) throws StorageHubException;
String setMetadata(String id,Metadata metadata) throws StorageHubException;
String setHidden(String id,Boolean value) throws StorageHubException;
String createGcubeItem(String parentId, GCubeItem item) throws StorageHubException;

View File

@ -18,6 +18,8 @@ import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer;
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
@ -31,15 +33,15 @@ public class Items {
@BeforeClass
public static void setUp(){
SecurityTokenProvider.instance.set("52e1492d-4bd1-4058-946f-d2fe5059ddc4-843339462");
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
ScopeProvider.instance.set("/gcube");
}
@Test
public void search() throws Exception{
StorageHubClient shc = new StorageHubClient();
List<? extends Item> s = shc.getWSRoot().search("pippo").getItems();
List<? extends Item> s = shc.getWSRoot().search("%data%").getItems();
s.forEach(i -> System.out.println(i.getPath()+" "+i.getName()));
}
@ -327,7 +329,17 @@ public class Items {
}
@Test
public void deleteUnusefulUsers() throws Exception{
final UserManagerClient client = AbstractPlugin.users().build();
List<String> users = client.getUsers();
StorageHubClient shc = new StorageHubClient();
for (String user : users)
if (user.startsWith("userm")) {
shc.deleteUserAccount(user);
System.out.println("user "+user+"removed");
}
}
/*