gcube-cms-suite/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/reports/Report.java

43 lines
1.1 KiB
Java
Raw Normal View History

2021-12-07 12:16:29 +01:00
package org.gcube.application.cms.plugins.reports;
2022-03-04 11:30:11 +01:00
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
2022-02-17 14:47:51 +01:00
import org.gcube.application.cms.plugins.faults.PluginExecutionException;
2021-12-07 12:16:29 +01:00
2022-01-17 13:30:21 +01:00
import java.util.ArrayList;
2021-12-07 12:16:29 +01:00
import java.util.List;
2022-03-04 11:30:11 +01:00
@Getter
@Setter
@NoArgsConstructor
2021-12-07 12:16:29 +01:00
public class Report {
public static enum Status {
ERROR,WARNING,OK
}
private Status status;
private List<String> messages;
2022-01-17 13:30:21 +01:00
2022-03-04 11:30:11 +01:00
public Report(Status status,String ... messages) {
this.status = status;
this.messages=new ArrayList<>();
for (String s : messages)
this.messages.add(s);
}
2022-01-17 13:30:21 +01:00
public Report putMessage(String msg){
if(messages==null)messages=new ArrayList<>();
messages.add(msg);
return this;
}
2022-02-17 14:47:51 +01:00
public void validate()throws PluginExecutionException {
if(status == null) throw new PluginExecutionException("Status is null");
if(!status.equals(Status.OK))
if(messages==null || messages.isEmpty()) throw new PluginExecutionException("Messages are mandatory for status != OK ");
}
2021-12-07 12:16:29 +01:00
}