@ -3,14 +3,50 @@ package de.srsoftware.umbrella.documents.model;
@@ -3,14 +3,50 @@ package de.srsoftware.umbrella.documents.model;
import static de.srsoftware.umbrella.core.Constants.* ;
import static de.srsoftware.umbrella.documents.Constants.* ;
import de.srsoftware.tools.Mappable ;
import org.json.JSONObject ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.util.HashSet ;
import java.util.Map ;
public record CustomerSettings ( String header , String footer , String mailText ) implements Mappable {
public class CustomerSettings implements Mappable {
private static final System . Logger LOG = System . getLogger ( CustomerSettings . class . getSimpleName ( ) ) ;
private String footer , header , mailText ;
private HashSet < String > dirtyFields = new HashSet < > ( ) ;
public CustomerSettings ( String header , String footer , String mailText ) {
this . header = header ;
this . footer = footer ;
this . mailText = mailText ;
}
public CustomerSettings clear ( ) {
dirtyFields . clear ( ) ;
return this ;
}
public static CustomerSettings empty ( ) {
return new CustomerSettings ( "" , "" , "" ) ;
}
public String footer ( ) {
return footer ;
}
public String header ( ) {
return header ;
}
public boolean isDirty ( ) {
return ! dirtyFields . isEmpty ( ) ;
}
public String mailText ( ) {
return mailText ;
}
public static CustomerSettings of ( ResultSet rs ) throws SQLException {
var header = rs . getString ( FIELD_DEFAULT_HEADER ) ;
var footer = rs . getString ( FIELD_DEFAULT_FOOTER ) ;
@ -18,12 +54,24 @@ public record CustomerSettings(String header, String footer, String mailText) im
@@ -18,12 +54,24 @@ public record CustomerSettings(String header, String footer, String mailText) im
return new CustomerSettings ( header , footer , mailText ) ;
}
public static CustomerSettings empty ( ) {
return new CustomerSettings ( "" , "" , "" ) ;
}
@Override
public Map < String , Object > toMap ( ) {
return Map . of ( FIELD_FOOTER , footer , FIELD_HEAD , header , CONTENT , mailText ) ;
}
public CustomerSettings patch ( JSONObject json ) {
for ( var key : json . keySet ( ) ) {
var valid = true ;
switch ( key ) {
case FIELD_FOOTER :
footer = json . getString ( key ) ; break ;
case FIELD_HEAD :
header = json . getString ( key ) ; break ;
default :
valid = false ;
}
if ( valid ) dirtyFields . add ( key ) ;
}
return this ;
}
}