86 lines
2.1 KiB
Java
86 lines
2.1 KiB
Java
package org.gcube.application.cms.plugins.events;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map.Entry;
|
|
|
|
import org.bson.Document;
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
|
import org.gcube.application.geoportal.common.model.document.accounting.Context;
|
|
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.Setter;
|
|
import lombok.ToString;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@Getter
|
|
@Setter
|
|
@NoArgsConstructor
|
|
@AllArgsConstructor
|
|
@Slf4j
|
|
@ToString
|
|
public class ItemObserved<T extends Project> implements ItemObservable {
|
|
|
|
private User userCaller;
|
|
private Context context;
|
|
private UseCaseDescriptor useCaseDescriptor;
|
|
private T project;
|
|
private EventManager.Event event;
|
|
private Document optional;
|
|
|
|
public String getProjectId() {
|
|
log.debug("Called getProjectId");
|
|
if (project == null)
|
|
return null;
|
|
return project.getId();
|
|
}
|
|
|
|
@Override
|
|
public String getUCD_Id() {
|
|
log.debug("Called getUCD_Id");
|
|
if (useCaseDescriptor == null)
|
|
return null;
|
|
return useCaseDescriptor.getId();
|
|
}
|
|
|
|
public LinkedHashMap<String, Object> getDocumentEntries(int limit) {
|
|
|
|
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<>();
|
|
|
|
try {
|
|
|
|
Iterator<Entry<String, Object>> entrySetsIt = project.getTheDocument().entrySet().iterator();
|
|
int i = 0;
|
|
while (entrySetsIt.hasNext()) {
|
|
if (i + 1 > limit)
|
|
break;
|
|
|
|
Entry<String, Object> entry = entrySetsIt.next();
|
|
documentAsMap.put(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null);
|
|
i++;
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
throw e;
|
|
}
|
|
|
|
return documentAsMap;
|
|
}
|
|
|
|
public void setOptionalMessage(String message){
|
|
this.optional = new Document();
|
|
this.optional.put("message", message);
|
|
}
|
|
|
|
public String getOptionalMessage(){
|
|
if(this.optional!=null) {
|
|
return (String) this.optional.getOrDefault("message", null);
|
|
}
|
|
return null;
|
|
}
|
|
}
|