Search in sources :

Example 1 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class SimpleAccountPreferencesService method getOneById.

@Override
public AccountPreferences getOneById(Long id, IdentityUser user) {
    AccountPreferences accountPreferences = repository.findOne(id);
    if (!user.getRoles().contains(IdentityUserRole.ADMIN)) {
        throw new BadRequestException("AccountPreferences are only available for admin users!");
    } else if (accountPreferences == null) {
        throw new BadRequestException(String.format("AccountPreferences could not find with id: %s", id));
    } else if (!accountPreferences.getAccount().equals(user.getAccount())) {
        throw new BadRequestException("AccountPreferences are only available for the owner admin user!");
    }
    authorizationService.hasReadPermission(accountPreferences);
    return accountPreferences;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 2 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class SimpleAccountPreferencesService method createDefaultAccountPreferences.

private AccountPreferences createDefaultAccountPreferences(String account) {
    AccountPreferences defaultPreferences = new AccountPreferences();
    defaultPreferences.setAccount(account);
    defaultPreferences.setMaxNumberOfClusters(ZERO);
    defaultPreferences.setMaxNumberOfNodesPerCluster(ZERO);
    defaultPreferences.setMaxNumberOfClustersPerUser(ZERO);
    defaultPreferences.setAllowedInstanceTypes(Collections.emptyList());
    defaultPreferences.setClusterTimeToLive(ZERO);
    defaultPreferences.setUserTimeToLive(ZERO);
    return defaultPreferences;
}
Also used : AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 3 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class SimpleAccountPreferencesService method delete.

@Override
public void delete(IdentityUser user) {
    AccountPreferences preferences = getOneByAccount(user);
    repository.delete(preferences);
}
Also used : AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 4 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class AccountPreferencesRequestToAccountPreferencesConverter method convert.

@Override
public AccountPreferences convert(AccountPreferencesJson source) {
    AccountPreferences target = new AccountPreferences();
    target.setMaxNumberOfClusters(source.getMaxNumberOfClusters());
    target.setMaxNumberOfNodesPerCluster(source.getMaxNumberOfNodesPerCluster());
    List<String> allowedInstanceTypes = source.getAllowedInstanceTypes();
    if (allowedInstanceTypes != null && !allowedInstanceTypes.isEmpty()) {
        target.setAllowedInstanceTypes(allowedInstanceTypes);
    }
    target.setClusterTimeToLive(source.getClusterTimeToLive() * HOUR_IN_MS);
    target.setUserTimeToLive(source.getUserTimeToLive() * HOUR_IN_MS);
    target.setMaxNumberOfClustersPerUser(source.getMaxNumberOfClustersPerUser());
    target.setPlatforms(source.getPlatforms());
    target.setDefaultTags(getTags(source.getDefaultTags()));
    return target;
}
Also used : AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 5 with AccountPreferences

use of com.sequenceiq.cloudbreak.domain.AccountPreferences in project cloudbreak by hortonworks.

the class AccountPreferencesController method get.

@Override
public AccountPreferencesJson get() {
    IdentityUser user = authenticatedUserService.getCbUser();
    AccountPreferences preferences = service.getOneByAccount(user);
    return convert(preferences);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Aggregations

AccountPreferences (com.sequenceiq.cloudbreak.domain.AccountPreferences)9 HashMap (java.util.HashMap)2 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1