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 org.openecomp.conflicts.dao.ConflictsDaoFactory;
20 import org.openecomp.conflicts.impl.VspMergeHandler;
21 import org.openecomp.sdc.common.errors.CoreException;
22 import org.openecomp.sdc.datatypes.model.ItemType;
23 import org.openecomp.sdc.vendorsoftwareproduct.dao.VspMergeDaoFactory;
24 import org.openecomp.sdc.versioning.AsdcItemManagerFactory;
25 import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
26 import org.openecomp.sdc.versioning.types.Item;
28 import java.util.HashMap;
30 import java.util.Optional;
32 public class ItemMergeHandlerFactoryImpl extends ItemMergeHandlerFactory {
33 // TODO: 11/1/2017 read this map from configuration, move Vsp merge handler to vsp lib, rearrange lib deps
34 private static final Map<ItemType, ItemMergeHandler> MERGE_HANDLER_BY_ITEM_TYPE =
38 MERGE_HANDLER_BY_ITEM_TYPE.put(ItemType.vsp,
39 new VspMergeHandler(ConflictsDaoFactory.getInstance().createInterface(),
40 VspMergeDaoFactory.getInstance().createInterface()));
44 public Optional<ItemMergeHandler> createInterface(String itemId) {
45 Item item = AsdcItemManagerFactory.getInstance().createInterface().get(itemId);
47 throw new CoreException(new EntityNotExistErrorBuilder("", itemId).build());
49 return Optional.ofNullable(MERGE_HANDLER_BY_ITEM_TYPE.get(ItemType.valueOf(item.getType())));
53 public ItemMergeHandler createInterface() {
54 return null; // call the one with the item id arg