use of org.springframework.dao.DataIntegrityViolationException in project ma-core-public by infiniteautomation.
the class UserDao method updateUser.
void updateUser(User user) {
// Potential fix for "An attempt was made to get a data value of type 'VARCHAR' from a data value of type 'null'"
if (user.getPhone() == null)
user.setPhone("");
if (user.getHomeUrl() == null)
user.setHomeUrl("");
if (user.getTimezone() == null)
user.setTimezone("");
if (user.getName() == null)
user.setName("");
if (user.getLocale() == null)
user.setLocale("");
int originalPwVersion = user.getPasswordVersion();
try {
User old = getTransactionTemplate().execute(new TransactionCallback<User>() {
@Override
public User doInTransaction(TransactionStatus status) {
User old = getUser(user.getId());
if (old == null) {
return null;
}
boolean passwordChanged = !old.getPassword().equals(user.getPassword());
if (passwordChanged) {
user.setPasswordVersion(old.getPasswordVersion() + 1);
} else {
user.setPasswordVersion(old.getPasswordVersion());
}
ejt.update(USER_UPDATE, new Object[] { user.getUsername(), user.getPassword(), user.getEmail(), user.getPhone(), boolToChar(user.isDisabled()), user.getHomeUrl(), user.getReceiveAlarmEmails(), boolToChar(user.isReceiveOwnAuditEvents()), user.getTimezone(), boolToChar(user.isMuted()), user.getPermissions(), user.getName(), user.getLocale(), user.getPasswordVersion(), user.getId() }, new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER });
return old;
}
});
if (old == null) {
throw new NotFoundException();
}
AuditEventType.raiseChangedEvent(AuditEventType.TYPE_USER, old, user);
boolean permissionsChanged = !old.getPermissions().equals(user.getPermissions());
if (user.getPasswordVersion() > originalPwVersion || permissionsChanged || user.isDisabled()) {
MangoSecurityConfiguration.sessionRegistry.exireSessionsForUser(old);
}
userCache.remove(old.getUsername());
if (handler != null)
handler.notify("update", user);
} catch (DataIntegrityViolationException e) {
// Log some information about the user object.
LOG.error("Error updating user: " + user, e);
throw e;
}
}
use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.
the class NetworkService method create.
@Transactional(TxType.NEVER)
public Network create(IdentityUser user, Network network) {
LOGGER.info("Creating network: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
network.setOwner(user.getUserId());
network.setAccount(user.getAccount());
try {
return networkRepository.save(network);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.NETWORK, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.
the class BlueprintService method create.
@Transactional(TxType.NEVER)
public Blueprint create(IdentityUser user, Blueprint blueprint, Collection<Map<String, Map<String, String>>> properties) {
LOGGER.debug("Creating blueprint: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
Blueprint savedBlueprint;
blueprint.setOwner(user.getUserId());
blueprint.setAccount(user.getAccount());
if (properties != null && !properties.isEmpty()) {
LOGGER.info("Extend validation with the following properties: {}", properties);
Map<String, Map<String, String>> configs = new HashMap<>(properties.size());
for (Map<String, Map<String, String>> property : properties) {
for (Entry<String, Map<String, String>> entry : property.entrySet()) {
Map<String, String> configValues = configs.get(entry.getKey());
if (configValues != null) {
configValues.putAll(entry.getValue());
} else {
configs.put(entry.getKey(), entry.getValue());
}
}
}
String extendedBlueprint = blueprintProcessorFactory.get(blueprint.getBlueprintText()).extendBlueprintGlobalConfiguration(SiteConfigurations.fromMap(configs), false).asText();
LOGGER.info("Extended validation result: {}", extendedBlueprint);
blueprint.setBlueprintText(extendedBlueprint);
}
try {
savedBlueprint = blueprintRepository.save(blueprint);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.BLUEPRINT, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
return savedBlueprint;
}
use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.
the class AmbariClusterService method create.
@Override
@Transactional(TxType.NEVER)
public Cluster create(IdentityUser user, Stack stack, Cluster cluster, List<ClusterComponent> components) {
LOGGER.info("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
String stackName = stack.getName();
if (stack.getCluster() != null) {
throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
}
long start = System.currentTimeMillis();
if (clusterRepository.findByNameInAccount(cluster.getName(), user.getAccount()) != null) {
throw new DuplicateKeyValueException(APIResourceType.CLUSTER, cluster.getName());
}
LOGGER.info("Cluster name collision check took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
if (Status.CREATE_FAILED.equals(stack.getStatus())) {
throw new BadRequestException("Stack creation failed, cannot create cluster.");
}
start = System.currentTimeMillis();
for (HostGroup hostGroup : cluster.getHostGroups()) {
constraintRepository.save(hostGroup.getConstraint());
}
LOGGER.info("Host group constrainst saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
start = System.currentTimeMillis();
if (cluster.getFileSystem() != null) {
fileSystemRepository.save(cluster.getFileSystem());
}
LOGGER.info("Filesystem config saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
if (cluster.getKerberosConfig() != null) {
kerberosConfigRepository.save(cluster.getKerberosConfig());
}
cluster.setStack(stack);
cluster.setOwner(user.getUserId());
cluster.setAccount(user.getAccount());
stack.setCluster(cluster);
start = System.currentTimeMillis();
generateSignKeys(cluster.getGateway());
LOGGER.info("Sign key generated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
try {
start = System.currentTimeMillis();
cluster = clusterRepository.save(cluster);
LOGGER.info("Cluster object saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
clusterComponentConfigProvider.store(components, cluster);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
if (stack.isAvailable()) {
flowManager.triggerClusterInstall(stack.getId());
InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(cluster.getStatus()));
if (InMemoryStateStore.getStack(stack.getId()) == null) {
InMemoryStateStore.putStack(stack.getId(), statusToPollGroupConverter.convert(stack.getStatus()));
}
}
return cluster;
}
use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.
the class ClusterTemplateService method create.
@Transactional(TxType.NEVER)
public ClusterTemplate create(IdentityUser user, ClusterTemplate clusterTemplate) {
LOGGER.debug("Creating clusterTemplate: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
ClusterTemplate savedClusterTemplate;
clusterTemplate.setOwner(user.getUserId());
clusterTemplate.setAccount(user.getAccount());
try {
savedClusterTemplate = clusterTemplateRepository.save(clusterTemplate);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER_TEMPLATE, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
return savedClusterTemplate;
}
Aggregations