revised job notifications

This commit is contained in:
Massimiliano Assante 2022-04-27 18:29:33 +02:00
parent be9f36822f
commit 04493ed776
4 changed files with 70 additions and 199 deletions

View File

@ -1,147 +0,0 @@
package org.gcube.portal.social.networking.ws.inputs;
import javax.validation.constraints.NotNull;
import org.gcube.portal.databook.shared.JobStatusType;
import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.portal.social.networking.ws.providers.JobStatusTypeDeserializer;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.webcohesion.enunciate.metadata.DocumentationExample;
/**
* The job notification bean class.
*/
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
/**
* @label A job notification object
*/
public class JobNotificationBean {
@JsonProperty("recipient")
@NotNull(message="recipient cannot be missing")
/*
* @param "The recipient of the notification",
*/
@DocumentationExample("andrea.rossi")
private String recipient;
/*
* @param jobId The job's identifier, i.e. very likely a UUID
*/
@JsonProperty("job_id")
private String jobId;
@JsonProperty("job_name")
private String jobName;
@JsonProperty("service_name")
@NotNull(message="service_name cannot be missing")
/*
* @param serviceName The name of the service running the job
*/
private String serviceName;
@JsonProperty("status")
@JsonDeserialize(using=JobStatusTypeDeserializer.class)
@NotNull(message="status cannot be missing")
private JobStatusType status;
@JsonProperty("status_message")
private String statusMessage;
public JobNotificationBean() {
super();
}
/**
* @param recipient
* @param jobId
* @param jobName
* @param serviceName
* @param status
* @param statusMessage
*/
public JobNotificationBean(String recipient, String jobId, String jobName,
String serviceName, JobStatusType status, String statusMessage) {
super();
this.recipient = recipient;
this.jobId = jobId;
this.jobName = jobName;
this.serviceName = serviceName;
this.status = status;
this.statusMessage = statusMessage;
}
public String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getJobName() {
return jobName;
}
public void setJobName(String jobName) {
this.jobName = jobName;
}
public JobStatusType getStatus() {
return status;
}
public void setStatus(JobStatusType status) {
this.status = status;
}
public RunningJob getRunningJob(){
return new RunningJob(jobId, jobName, status, statusMessage, serviceName);
}
@Override
public String toString() {
return "JobNotificationBean ["
+ (recipient != null ? "recipient=" + recipient + ", " : "")
+ (jobId != null ? "jobId=" + jobId + ", " : "")
+ (jobName != null ? "jobName=" + jobName + ", " : "")
+ (serviceName != null ? "serviceName=" + serviceName + ", "
: "")
+ (status != null ? "status=" + status + ", " : "")
+ (statusMessage != null ? "statusMessage=" + statusMessage
: "") + "]";
}
}

View File

@ -0,0 +1,64 @@
package org.gcube.portal.social.networking.ws.mappers;
import org.gcube.portal.databook.shared.JobStatusType;
import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.JobStatusModelType;
public class JobMapper {
public JobMapper() {
}
public static RunningJob getJob(JobNotificationBean item) {
String jobId = null;
String jobName = null;
JobStatusType status = null;
String message = null;
String serviceName = null; // i.e., Dataminer, SmartExecutor..
try {
jobId = item.getJobId();
jobName = item.getJobName();
status = getType(item.getStatus());
message = item.getStatusMessage();
serviceName = item.getServiceName();
} catch (Exception e) {
e.printStackTrace();
}
return new RunningJob(jobId, jobName, status, message, serviceName);
}
public static JobStatusType getType(JobStatusModelType type) {
JobStatusType toReturn = null;
switch (type) {
case CANCELLED:
return JobStatusType.CANCELLED;
case DELETED:
return JobStatusType.DELETED;
case FAILED:
return JobStatusType.FAILED;
case CANCELLING:
return JobStatusType.CANCELLING;
case DELETING:
return JobStatusType.DELETING;
case EXECUTING:
return JobStatusType.EXECUTING;
case NEW:
return JobStatusType.NEW;
case SUBMITTED:
return JobStatusType.SUBMITTED;
case SUCCEEDED:
return JobStatusType.SUCCEEDED;
case TIMED_OUT:
return JobStatusType.TIMED_OUT;
case WAITING:
return JobStatusType.WAITING;
default:
break;
}
return toReturn;
}
}

View File

@ -20,29 +20,27 @@ import javax.ws.rs.core.Response.Status;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.portal.databook.shared.RunningJob;
import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.JobStatusNotificationThread;
import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder;
import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials;
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
import org.gcube.portal.social.networking.ws.inputs.JobNotificationBean;
import org.gcube.portal.social.networking.ws.mappers.JobMapper;
import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper;
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.WSAddedItemNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.WSSharedFolderNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.WSUnsharedFolderNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceFileItemBean;
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceNotificationMessage;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.LoggerFactory;
@ -149,7 +147,9 @@ public class Notifications {
SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
new Thread(new JobStatusNotificationThread(job.getRunningJob(), Arrays.asList(recipientBean), nm)).start();
RunningJob theJob = JobMapper.getJob(job);
new Thread(new JobStatusNotificationThread(theJob, Arrays.asList(recipientBean), nm)).start();
responseBean.setSuccess(true);
responseBean.setResult("Notification thread started");

View File

@ -1,46 +0,0 @@
package org.gcube.portal.social.networking.ws.providers;
import java.io.IOException;
import org.gcube.portal.databook.shared.JobStatusType;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
/**
* Deserializer used to map a string representing the status in this JobNotificationBean to the JobStatusType enum.
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
*/
public class JobStatusTypeDeserializer extends JsonDeserializer<JobStatusType>{
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(JobStatusTypeDeserializer.class);
@Override
public JobStatusType deserialize(JsonParser p,
DeserializationContext ctxt) throws IOException,
JsonProcessingException {
logger.debug("Status deserializer called");
String status = p.getText();
JobStatusType toReturn = null;
logger.debug("Status coming from json object is " + status);
JobStatusType[] values = JobStatusType.values();
for (JobStatusType jobStatusType : values) {
if(jobStatusType.toString().toLowerCase().contains(status.toLowerCase())){
toReturn = jobStatusType;
break;
}
}
logger.debug("JOB STATUS deserialized as " + toReturn);
return toReturn;
}
}