2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.conflicts;
19 import java.util.HashMap;
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;
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 =
37 MERGE_HANDLER_BY_ITEM_TYPE.put(ItemType.vsp,
38 new VspMergeHandler(ConflictsDaoFactory.getInstance().createInterface(),
39 VspMergeDaoFactory.getInstance().createInterface()));
43 public Optional<ItemMergeHandler> createInterface(String itemId) {
44 Item item = AsdcItemManagerFactory.getInstance().createInterface().get(itemId);
46 throw new CoreException(new EntityNotExistErrorBuilder("", itemId).build());
48 return Optional.ofNullable(MERGE_HANDLER_BY_ITEM_TYPE.get(ItemType.valueOf(item.getType())));
52 public ItemMergeHandler createInterface() {
53 return null; // call the one with the item id arg