push addional code
[sdc.git] / openecomp-be / lib / openecomp-sdc-versioning-lib / openecomp-sdc-versioning-api / src / main / java / org / openecomp / sdc / versioning / errors / VersionableSubEntityNotFoundErrorBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.versioning.errors;
22
23 import org.openecomp.core.utilities.CommonMethods;
24 import org.openecomp.sdc.common.errors.BaseErrorBuilder;
25 import org.openecomp.sdc.common.errors.ErrorCategory;
26 import org.openecomp.sdc.versioning.dao.types.Version;
27
28 import java.util.List;
29
30 /**
31  * The type Versionable sub entity not found error builder.
32  */
33 public class VersionableSubEntityNotFoundErrorBuilder extends BaseErrorBuilder {
34
35   private static final String SUB_ENTITY_NOT_FOUND_MSG =
36       "%s with Id %s does not exist for %s with id %s and version %s";
37   private static final String SUB_ENTITIES_NOT_FOUND_MSG =
38       "%ss with Ids %s do not exist for %s with id %s and version %s";
39
40   /**
41    * Instantiates a new Versionable sub entity not found error builder.
42    *
43    * @param entityType           the entity type
44    * @param entityId             the entity id
45    * @param containingEntityType the containing entity type
46    * @param containingEntityId   the containing entity id
47    * @param version              the version
48    */
49   public VersionableSubEntityNotFoundErrorBuilder(String entityType, String entityId,
50                                                   String containingEntityType,
51                                                   String containingEntityId, Version version) {
52     getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
53     getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
54     getErrorCodeBuilder().withMessage(String
55         .format(SUB_ENTITY_NOT_FOUND_MSG, entityType, entityId, containingEntityType,
56             containingEntityId, version.toString()));
57   }
58
59   /**
60    * Instantiates a new Versionable sub entity not found error builder.
61    *
62    * @param entityType           the entity type
63    * @param entityIds            the entity ids
64    * @param containingEntityType the containing entity type
65    * @param containingEntityId   the containing entity id
66    * @param version              the version
67    */
68   public VersionableSubEntityNotFoundErrorBuilder(String entityType, List<String> entityIds,
69                                                   String containingEntityType,
70                                                   String containingEntityId, Version version) {
71     getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
72     getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
73     getErrorCodeBuilder().withMessage(String.format(SUB_ENTITIES_NOT_FOUND_MSG, entityType,
74         CommonMethods.listToSeparatedString(entityIds, ','), containingEntityType,
75         containingEntityId, version.toString()));
76   }
77 }