preparing to update item base data
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -4,11 +4,14 @@ package de.srsoftware.umbrella.core.model;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Item implements Mappable {
|
||||
private long id;
|
||||
@@ -16,6 +19,7 @@ public class Item implements Mappable {
|
||||
private String code, name;
|
||||
private Location location;
|
||||
private Collection<Property> properties;
|
||||
private Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
private Item(Mappable owner, long id, Location location, String code, String name) {
|
||||
this.owner = owner;
|
||||
@@ -26,6 +30,10 @@ public class Item implements Mappable {
|
||||
this.properties = new HashSet<>();
|
||||
}
|
||||
|
||||
public boolean isDirty(){
|
||||
return !dirtyFields.isEmpty();
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
@@ -62,4 +70,19 @@ public class Item implements Mappable {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Item patch(JSONObject json) {
|
||||
for (var field : json.keySet()){
|
||||
var known = true;
|
||||
switch (field) {
|
||||
case NAME:
|
||||
name = json.getString(field);
|
||||
break;
|
||||
default:
|
||||
known = false;
|
||||
}
|
||||
if (known) dirtyFields.add(field);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user