|
|
|
|
@@ -18,6 +18,7 @@ public class Poll implements Mappable {
|
|
|
|
|
public static class Option implements Mappable{
|
|
|
|
|
|
|
|
|
|
private int id;
|
|
|
|
|
|
|
|
|
|
Integer status;
|
|
|
|
|
private String description;
|
|
|
|
|
private String name;
|
|
|
|
|
@@ -28,7 +29,6 @@ public class Poll implements Mappable {
|
|
|
|
|
this.description = description;
|
|
|
|
|
this.status = status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String description(){
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
@@ -104,11 +104,11 @@ public class Poll implements Mappable {
|
|
|
|
|
return format("Option \"{0}\"",name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public static class Evaluation {
|
|
|
|
|
// Map<Option → Map<Weight → Count>>
|
|
|
|
|
private HashMap<Integer,Map<Integer,Integer>> selections = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
public void count(ResultSet rs) throws SQLException {
|
|
|
|
|
var optionId = rs.getInt(OPTION_ID);
|
|
|
|
|
var userId = rs.getObject(USER_ID);
|
|
|
|
|
@@ -120,16 +120,17 @@ public class Poll implements Mappable {
|
|
|
|
|
public HashMap<Integer, Map<Integer, Integer>> toMap() {
|
|
|
|
|
return selections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private Owner owner;
|
|
|
|
|
|
|
|
|
|
private String id, name, description;
|
|
|
|
|
|
|
|
|
|
private boolean isPrivate;
|
|
|
|
|
private List<Option> options;
|
|
|
|
|
private Map<Integer,String> weights;
|
|
|
|
|
private Map<UmbrellaUser,Long> shares;
|
|
|
|
|
private Map<UmbrellaUser,Permission> permissions;
|
|
|
|
|
private Set<String> dirtyFields = new HashSet<>();
|
|
|
|
|
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights, Map<UmbrellaUser,Long> shares){
|
|
|
|
|
public Poll(String id, Owner owner, String name, String description, boolean isPrivate, List<Option> options, Map<Integer,String> weights){
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.owner = owner;
|
|
|
|
|
this.name = name;
|
|
|
|
|
@@ -137,9 +138,8 @@ public class Poll implements Mappable {
|
|
|
|
|
this.isPrivate = isPrivate;
|
|
|
|
|
this.options = new ArrayList<>();
|
|
|
|
|
this.weights = new HashMap<>();
|
|
|
|
|
this.shares = new HashMap<>();
|
|
|
|
|
this.permissions = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String description(){
|
|
|
|
|
return description;
|
|
|
|
|
}
|
|
|
|
|
@@ -169,12 +169,12 @@ public class Poll implements Mappable {
|
|
|
|
|
return isPrivate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<Long, Map<String, Object>> mapShares() {
|
|
|
|
|
private Map<Long, Map<String, Object>> mapPermissions() {
|
|
|
|
|
var result = new HashMap<Long,Map<String,Object>>();
|
|
|
|
|
for (var entry : shares.entrySet()){
|
|
|
|
|
for (var entry : permissions.entrySet()){
|
|
|
|
|
var user = entry.getKey();
|
|
|
|
|
var data = user.toMap();
|
|
|
|
|
data.put(Field.PERMISSION,entry.getValue());
|
|
|
|
|
data.put(Field.PERMISSION,entry.getValue().toMap());
|
|
|
|
|
result.put(user.id(),data);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
@@ -198,7 +198,7 @@ public class Poll implements Mappable {
|
|
|
|
|
var isPrivate = rs.getBoolean(Field.PRIVATE);
|
|
|
|
|
var owner = ModuleRegistry.userService().loadUser(userId);
|
|
|
|
|
|
|
|
|
|
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>(),new HashMap<>());
|
|
|
|
|
return new Poll(id,owner,name,description,isPrivate,new ArrayList<>(),new HashMap<>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Option> options(){
|
|
|
|
|
@@ -209,14 +209,20 @@ public class Poll implements Mappable {
|
|
|
|
|
return owner;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Poll setPrivate(boolean newValue) {
|
|
|
|
|
if (newValue != isPrivate) dirtyFields.add(PRIVATE);
|
|
|
|
|
isPrivate = newValue;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Poll setWeight(Integer weight, String description) {
|
|
|
|
|
weights.put(weight,description);
|
|
|
|
|
dirtyFields.add(WEIGHTS);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<UmbrellaUser, Long> shares(){
|
|
|
|
|
return shares;
|
|
|
|
|
public Map<UmbrellaUser, Permission> permissions(){
|
|
|
|
|
return permissions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -230,7 +236,7 @@ public class Poll implements Mappable {
|
|
|
|
|
Field.RENDERED,Util.markdown(description)
|
|
|
|
|
),
|
|
|
|
|
Field.OPTIONS, options.stream().collect(Collectors.toMap(Option::id,Option::toMap)),
|
|
|
|
|
Field.SHARES, mapShares(),
|
|
|
|
|
Field.PERMISSION, mapPermissions(),
|
|
|
|
|
Field.PRIVATE, isPrivate,
|
|
|
|
|
Field.WEIGHTS, weights
|
|
|
|
|
);
|
|
|
|
|
|