edu.internet2.middleware.grouper.attr.AttributeDefNameSaveBatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grouper Show documentation
Show all versions of grouper Show documentation
Internet2 Groups Management Toolkit
package edu.internet2.middleware.grouper.attr;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import edu.internet2.middleware.grouper.attr.finder.AttributeDefNameFinder;
import edu.internet2.middleware.grouper.util.GrouperUtil;
public class AttributeDefNameSaveBatch {
private boolean makeChangesIfExist = true;
public AttributeDefNameSaveBatch assignMakeChangesIfExist(boolean theMakeChangesIfExist) {
this.makeChangesIfExist = theMakeChangesIfExist;
return this;
}
private List attributeDefNameSaves = new ArrayList();
public AttributeDefNameSaveBatch addAttributeDefNameSaves(Collection theAttributeDefNameSaves) {
if (theAttributeDefNameSaves != null) {
this.attributeDefNameSaves.addAll(theAttributeDefNameSaves);
}
return this;
}
public Map save() {
Set nameOfAttributeDefNames = new HashSet();
for (AttributeDefNameSave attributeDefNameSave : attributeDefNameSaves) {
if (!StringUtils.isBlank(attributeDefNameSave.getName())) {
nameOfAttributeDefNames.add(attributeDefNameSave.getName());
}
if (!StringUtils.isBlank(attributeDefNameSave.getAttributeDefNameNameToEdit())) {
nameOfAttributeDefNames.add(attributeDefNameSave.getAttributeDefNameNameToEdit());
}
}
Set attributeDefNames = new AttributeDefNameFinder().assignNamesOfAttributeDefNames(nameOfAttributeDefNames).findAttributeNames();
Map nameOfAttributeDefNameToAttributeDefName = new HashMap();
for (AttributeDefName attributeDefName : GrouperUtil.nonNull(attributeDefNames)) {
nameOfAttributeDefNameToAttributeDefName.put(attributeDefName.getName(), attributeDefName);
}
for (AttributeDefNameSave attributeDefNameSave : attributeDefNameSaves) {
if (!StringUtils.isBlank(attributeDefNameSave.getName())) {
AttributeDefName attributeDefName = nameOfAttributeDefNameToAttributeDefName.get(attributeDefNameSave.getName());
if (attributeDefName != null) {
if (this.makeChangesIfExist) {
attributeDefName = attributeDefNameSave.save();
}
} else {
attributeDefName = attributeDefNameSave.save();
}
if (attributeDefName != null) {
nameOfAttributeDefNameToAttributeDefName.put(attributeDefName.getName(), attributeDefName);
}
}
}
return nameOfAttributeDefNameToAttributeDefName;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy