HostVariableAPI hostVariableAPI = APILocator.getHostVariableAPI();
List<HostVariable> variables = hostVariableAPI.getVariablesForHost(hostId, user, false);
HostVariable hostVariable = null;
for (HostVariable next : variables) {
if (next.getKey().equals(key) && !next.getId().equals(id)) {
return LanguageUtil.get(user, "message.hostvariables.exist.error.key");
}
if(UtilMethods.isSet(id) && next.getId().equals(id)) {
hostVariable = next;
}
}
if(hostVariable == null) {
hostVariable = new HostVariable();
}
hostVariable.setId(id);
hostVariable.setHostId(hostId);
hostVariable.setName(name);
hostVariable.setKey(key);
hostVariable.setValue(value);
hostVariable.setLastModifierId(user.getUserId());
hostVariable.setLastModDate(new Date());
try {
hostVariableAPI.save(hostVariable, user, respectFrontendRoles);
} catch (DotSecurityException e) {
return LanguageUtil.get(user, "message.hostvariables.permission.error.save");
}