1e3213a9536c4471ab16eb6946bddabf9640d2fa
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.conflicts;
18
19 import java.util.HashMap;
20 import java.util.Map;
21 import java.util.Optional;
22 import org.openecomp.conflicts.dao.ConflictsDaoFactory;
23 import org.openecomp.conflicts.impl.VspMergeHandler;
24 import org.openecomp.sdc.common.errors.CoreException;
25 import org.openecomp.sdc.datatypes.model.ItemType;
26 import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDaoFactory;
27 import org.openecomp.sdc.versioning.AsdcItemManagerFactory;
28 import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
29 import org.openecomp.sdc.versioning.types.Item;
30
31 public class ItemMergeHandlerFactoryImpl extends ItemMergeHandlerFactory {
32   // TODO: 11/1/2017 read this map from configuration, move Vsp merge handler to vsp lib, rearrange lib deps
33   private static final Map<ItemType, ItemMergeHandler> MERGE_HANDLER_BY_ITEM_TYPE =
34       new HashMap<>();
35
36   static {
37     MERGE_HANDLER_BY_ITEM_TYPE.put(ItemType.vsp,
38         new VspMergeHandler(ConflictsDaoFactory.getInstance().createInterface(),
39             VspMergeDaoFactory.getInstance().createInterface()));
40   }
41
42   @Override
43   public Optional<ItemMergeHandler> createInterface(String itemId) {
44     Item item = AsdcItemManagerFactory.getInstance().createInterface().get(itemId);
45     if (item == null) {
46       throw new CoreException(new EntityNotExistErrorBuilder("", itemId).build());
47     }
48     return Optional.ofNullable(MERGE_HANDLER_BY_ITEM_TYPE.get(ItemType.valueOf(item.getType())));
49   }
50
51   @Override
52   public ItemMergeHandler createInterface() {
53     return null; // call the one with the item id arg
54   }
55 }