summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/AccessValidations.java
blob: da098acb13b80510d84f0d78a2440331cff36e30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.openecomp.sdc.be.components.validation;

import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.exception.ResponseFormat;

@org.springframework.stereotype.Component
public class AccessValidations {

    private final UserValidations userValidations;
    private final ComponentValidations componentValidations;


    public AccessValidations(UserValidations userValidations, ComponentValidations componentValidations) {
        this.userValidations = userValidations;
        this.componentValidations = componentValidations;
    }

    public Component validateUserCanWorkOnComponentAndLockIt(ComponentTypeEnum componentTypeEnum, String componentId, String userId, String actionContext) {
        userValidations.validateUserExists(userId, actionContext, false)
                .left()
                .on(this::onUserError);

        return componentValidations.validateComponentIsCheckedOutByUserAndLockIt(componentTypeEnum, componentId, userId);
    }

    private User onUserError(ResponseFormat responseFormat) {
        throw new ComponentException(responseFormat);
    }


}