Compare commits
2 Commits
master
...
master_rem
Author | SHA1 | Date |
---|---|---|
lucio | 7d760b566c | |
lucio | 1774f8addf |
|
@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
## [v2.0.0]
|
||||
|
||||
- messages interface removed
|
||||
|
||||
### Feature
|
||||
|
||||
porting to model 2.0
|
||||
|
|
|
@ -11,7 +11,6 @@ import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
|||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
|
||||
|
@ -24,7 +23,6 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
|||
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
||||
private static final UserManagerPlugin user_plugin = new UserManagerPlugin();
|
||||
private static final GroupManagerPlugin group_plugin = new GroupManagerPlugin();
|
||||
private static final MessageManagerPlugin messages_plugin = new MessageManagerPlugin();
|
||||
|
||||
|
||||
public static ProxyBuilder<ItemManagerClient> item() {
|
||||
|
@ -44,9 +42,6 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
|||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,WorkspaceManagerClient>(workspace_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<MessageManagerClient> messages() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,MessageManagerClient>(messages_plugin);
|
||||
}
|
||||
|
||||
public final String name;
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||
import org.gcube.common.clients.config.ProxyConfig;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultMessageManager;
|
||||
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class MessageManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, MessageManagerClient> {
|
||||
|
||||
public MessageManagerPlugin() {
|
||||
super("storagehub/workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
return new DefaultMessageManager(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||
throws Exception {
|
||||
DOMResult result = new DOMResult();
|
||||
epr.writeTo(result);
|
||||
Node node =result.getNode();
|
||||
Node child=node.getFirstChild();
|
||||
String address = child.getTextContent();
|
||||
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("messages");
|
||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||
requestAdapter.register(MyInputStreamProvider.class);
|
||||
requestAdapter.register(MultiPartFeature.class);
|
||||
customClasses.forEach(c -> requestAdapter.register(c));
|
||||
return requestAdapter;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.messages.Message;
|
||||
import org.gcube.common.storagehub.model.service.ItemList;
|
||||
import org.gcube.common.storagehub.model.types.MessageList;
|
||||
|
||||
public class DefaultMessageManager extends DefaultManagerClient implements MessageManagerClient {
|
||||
|
||||
|
||||
public DefaultMessageManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message get(String id) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Message> call = new Call<GXWebTargetAdapterRequest, Message>() {
|
||||
@Override
|
||||
public Message call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||
}
|
||||
|
||||
Message item = response.getSource().readEntity(Message.class);
|
||||
|
||||
|
||||
return item;
|
||||
}
|
||||
};
|
||||
try {
|
||||
return delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> getReceivedMessages(int reduceBody) throws StorageHubException {
|
||||
return getMessages("inbox", reduceBody);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> getSentMessages(int reduceBody) throws StorageHubException {
|
||||
return getMessages("sent", reduceBody);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> getReceivedMessages() throws StorageHubException {
|
||||
return getMessages("inbox", -1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Message> getSentMessages() throws StorageHubException {
|
||||
return getMessages("sent", -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRead(String id, Boolean value) throws StorageHubException {
|
||||
setBooleanProp("hl:read", value, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOpened(String id, Boolean value) throws StorageHubException {
|
||||
setBooleanProp("hl:open", value, id);
|
||||
}
|
||||
|
||||
|
||||
private void setBooleanProp(String prop, Boolean bool, String id) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id).path(prop);
|
||||
|
||||
GXInboundResponse response = myManager.put(Entity.json(bool));
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sendMessage(List<String> recipients, String subject, String body, List<String> attachments) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(recipients, "recipients cannot be null");
|
||||
Objects.requireNonNull(subject, "subject cannot be null");
|
||||
Objects.requireNonNull(body, "body cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path("send");
|
||||
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>();
|
||||
|
||||
recipients.forEach(r-> formData.add("to[]", r));
|
||||
formData.add("subject", subject);
|
||||
formData.add("body", body);
|
||||
if (attachments!=null)
|
||||
attachments.forEach(a -> formData.add("attachments[]", a));
|
||||
|
||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
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 void delete(String id) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(id, "id cannot be null");
|
||||
GXWebTargetAdapterRequest myManager = manager.path(id);
|
||||
|
||||
GXInboundResponse response = myManager.delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<? extends Item> getAttachments(String messageId) throws StorageHubException{
|
||||
Call<GXWebTargetAdapterRequest, ItemList> call = new Call<GXWebTargetAdapterRequest, ItemList>() {
|
||||
@Override
|
||||
public ItemList call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager.path(messageId).path("attachments");
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(ItemList.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
return delegate.make(call).getItemlist();
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<Message> getMessages(final String path, int reduceBody ) throws StorageHubException{
|
||||
Call<GXWebTargetAdapterRequest, List<Message>> call = new Call<GXWebTargetAdapterRequest, List<Message>>() {
|
||||
@Override
|
||||
public List<Message> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager.path(path);
|
||||
if (reduceBody>0)
|
||||
myManager.queryParams(Collections.singletonMap("reduceBody", new Object[]{reduceBody}));
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else if (response.getHTTPCode()==403)
|
||||
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
|
||||
return response.getSource().readEntity(MessageList.class).getMessages();
|
||||
}
|
||||
};
|
||||
try {
|
||||
return delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.messages.Message;
|
||||
|
||||
public interface MessageManagerClient extends ManagerClient{
|
||||
|
||||
Message get(String id) throws StorageHubException;
|
||||
|
||||
List<? extends Item> getAttachments(String id) throws StorageHubException;
|
||||
|
||||
List<Message> getReceivedMessages(int reduceBody) throws StorageHubException;
|
||||
|
||||
List<Message> getSentMessages(int reduceBody) throws StorageHubException;
|
||||
|
||||
List<Message> getReceivedMessages() throws StorageHubException;
|
||||
|
||||
List<Message> getSentMessages() throws StorageHubException;
|
||||
|
||||
|
||||
void delete(String id) throws StorageHubException;
|
||||
|
||||
String sendMessage(List<String> recipients, String subject, String body, List<String> attachments)
|
||||
throws StorageHubException;
|
||||
|
||||
void setRead(String id, Boolean value) throws StorageHubException;
|
||||
|
||||
void setOpened(String id, Boolean value) throws StorageHubException;
|
||||
}
|
|
@ -21,7 +21,6 @@ import org.gcube.common.storagehub.client.StreamDescriptor;
|
|||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.MessageManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.Metadata;
|
||||
import org.gcube.common.storagehub.model.Paths;
|
||||
|
@ -72,17 +71,7 @@ public class TestCall {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sendMessagesWithAttachment() throws Exception {
|
||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUnread() throws Exception {
|
||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||
client.setRead("f3b7ce40-28df-40b3-ad17-f0b9bd658016", false);
|
||||
}
|
||||
|
||||
public void addUserToGroup() throws StorageHubException {
|
||||
GroupManagerClient client = AbstractPlugin.groups().build();
|
||||
|
|
Loading…
Reference in New Issue