Search in sources :

Example 86 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class TopologyService method create.

@Transactional(TxType.NEVER)
public Topology create(IdentityUser user, Topology topology) {
    LOGGER.debug("Creating topology: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    Topology savedTopology;
    topology.setOwner(user.getUserId());
    topology.setAccount(user.getAccount());
    try {
        savedTopology = topologyRepository.save(topology);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.TOPOLOGY, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    return savedTopology;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Topology(com.sequenceiq.cloudbreak.domain.Topology) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 87 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class UserProfileService method put.

public void put(UserProfileRequest request, IdentityUser user) {
    UserProfile userProfile = get(user.getAccount(), user.getUserId(), user.getUsername());
    if (request.getCredentialId() != null) {
        Credential credential = credentialService.get(request.getCredentialId(), userProfile.getAccount());
        userProfile.setCredential(credential);
    } else if (request.getCredentialName() != null) {
        Credential credential = credentialService.get(request.getCredentialName(), userProfile.getAccount());
        userProfile.setCredential(credential);
    }
    for (Entry<String, Object> uiStringObjectEntry : request.getUiProperties().entrySet()) {
        Map<String, Object> map = userProfile.getUiProperties().getMap();
        if (map == null || map.isEmpty()) {
            map = new HashMap<>();
        }
        map.put(uiStringObjectEntry.getKey(), uiStringObjectEntry.getValue());
        try {
            userProfile.setUiProperties(new Json(map));
        } catch (JsonProcessingException ignored) {
            throw new BadRequestException("The modification of the ui properties was unsuccesfull.");
        }
    }
    userProfileRepository.save(userProfile);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3