[New] Added ModelHelper to copy params

This commit is contained in:
Robert von Burg 2021-04-19 17:07:11 +02:00
parent 32662678e7
commit 69ae85ec34
1 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package li.strolch.model;
import static li.strolch.model.StrolchModelConstants.BAG_PARAMETERS;
import static li.strolch.model.StrolchModelConstants.BAG_RELATIONS;
import li.strolch.model.parameter.StringParameter;
/**
* Helper class to perform often performed model commands
*/
public class ModelHelper {
public static void copyExistingString(Resource src, Resource dst, String paramId) {
copyStringParam(src, dst, BAG_PARAMETERS, paramId);
}
public static void copyExistingRelation(Resource src, Resource dst, String paramId) {
copyStringParam(src, dst, BAG_RELATIONS, paramId);
}
public static void copyStringParam(Resource src, Resource dst, String bagId, String paramId) {
if (src.hasParameter(bagId, paramId) && !src.getStringP(bagId, paramId).isEmpty()) {
StringParameter existingBillingIdP = src.getStringP(bagId, paramId);
if (!dst.hasParameter(bagId, paramId)) {
dst.addParameter(existingBillingIdP.getClone());
} else if (dst.getStringP(bagId, paramId).isEmpty()) {
dst.setString(bagId, paramId, existingBillingIdP.getValue());
}
}
}
}