2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.dao.impl;
23 import fj.data.Either;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25 import org.openecomp.sdc.be.dao.api.IElementDAO;
26 import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
27 import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.dao.neo4j.Neo4jClient;
30 import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
31 import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
32 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
35 import java.util.List;
37 //@Component("elements-dao")
38 public class Neo4jElementDAO implements IElementDAO {
41 Neo4jClient neo4jClient;
43 private static Logger logger = Logger.getLogger(Neo4jElementDAO.class.getName());
46 public Either<List<GraphElement>, ActionStatus> getAllCategories() {
47 MatchFilter filter = new MatchFilter();
48 Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
49 NodeTypeEnum.ResourceCategory.getName(), filter);
50 if (status.isRight()) {
51 return Either.right(ActionStatus.GENERAL_ERROR);
53 List<GraphElement> value = status.left().value();
54 if (value == null || value.isEmpty()) {
55 return Either.right(ActionStatus.GENERAL_ERROR);
57 return Either.left(value);
63 public Either<List<GraphElement>, ActionStatus> getAllTags() {
64 MatchFilter filter = new MatchFilter();
65 Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
66 NodeTypeEnum.Tag.getName(), filter);
67 if (status.isRight()) {
68 return Either.right(ActionStatus.GENERAL_ERROR);
70 List<GraphElement> value = status.left().value();
72 return Either.right(ActionStatus.GENERAL_ERROR);
74 return Either.left(value);
80 public Either<GraphElement, ActionStatus> getCategory(String name) {
81 MatchFilter filter = new MatchFilter();
82 filter.addToMatch(GraphPropertiesDictionary.NAME.getProperty(), name);
83 Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
84 NodeTypeEnum.ResourceCategory.getName(), filter);
85 if (status.isRight()) {
86 return Either.right(ActionStatus.GENERAL_ERROR);
88 List<GraphElement> value = status.left().value();
90 return Either.right(ActionStatus.GENERAL_ERROR);
92 return Either.left(value.get(0));
103 public void setNeo4jClient(Neo4jClient neo4jClient) {
104 this.neo4jClient = neo4jClient;