summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java15
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java12
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java10
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java14
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java134
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java16
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java16
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java63
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java5
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java52
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java38
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java33
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java8
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java48
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java20
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java6
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java8
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java3
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java2
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java3
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java56
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/CassandraBaseDao.java42
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueCassandraDaoImpl.java54
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueDaoFactoryImpl.java16
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbFactoryImpl.java27
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java42
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java77
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java120
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java420
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java4
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java10
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java56
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/deserializers/RequirementDefinitionDeserializer.java115
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/exception/NewInstanceRuntimeException.java1
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java10
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java477
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java253
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java33
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java15
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/convertor/ElementConvertor.java36
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java100
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptorFactory.java11
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java64
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/AsdcElement.java226
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/ElementPropertyName.java3
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java81
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnectorFactory.java11
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorFactoryImpl.java20
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java594
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java18
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ItemElementLoggerTargetServiceName.java23
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorFactoryImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java452
61 files changed, 1792 insertions, 2222 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java
index 1d5fd16ee1..c1839373fd 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,20 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig;
+import java.util.Collection;
import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
-import java.util.Collection;
-
-
public interface ApplicationConfig {
- ConfigurationData getConfigurationData(String namespace, String key);
+ ConfigurationData getConfigurationData(String namespace, String key);
- void insertValue(String namespace, String key, String value);
+ void insertValue(String namespace, String key, String value);
- Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace);
+ Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java
index c751b98c7e..8865273fef 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,16 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig;
import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
-
public abstract class ApplicationConfigFactory extends AbstractComponentFactory<ApplicationConfig> {
- public static ApplicationConfigFactory getInstance() {
- return AbstractFactory.getInstance(ApplicationConfigFactory.class);
- }
+ public static ApplicationConfigFactory getInstance() {
+ return AbstractFactory.getInstance(ApplicationConfigFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java
index a4c582744a..028cff9de4 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,17 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.dao;
import org.openecomp.core.dao.BaseDao;
import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
-
public interface ApplicationConfigDao extends BaseDao<ApplicationConfigEntity> {
- long getValueTimestamp(String namespace, String key);
+ long getValueTimestamp(String namespace, String key);
- ConfigurationData getConfigurationData(String namespace, String key);
+ ConfigurationData getConfigurationData(String namespace, String key);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java
index f60e4a9010..0f03972fd5 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,16 +17,14 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.dao;
import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
-public abstract class ApplicationConfigDaoFactory
- extends AbstractComponentFactory<ApplicationConfigDao> {
+public abstract class ApplicationConfigDaoFactory extends AbstractComponentFactory<ApplicationConfigDao> {
- public static ApplicationConfigDaoFactory getInstance() {
- return AbstractFactory.getInstance(ApplicationConfigDaoFactory.class);
- }
+ public static ApplicationConfigDaoFactory getInstance() {
+ return AbstractFactory.getInstance(ApplicationConfigDaoFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java
index b7cd576557..926266bd0a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.dao.impl;
import com.datastax.driver.core.ResultSet;
@@ -26,6 +25,8 @@ import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.Result;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;
+import java.util.Collection;
+import java.util.Objects;
import org.openecomp.core.dao.impl.CassandraBaseDao;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
@@ -33,85 +34,72 @@ import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity;
import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData;
-import java.util.Collection;
-import java.util.Objects;
+public class ApplicationConfigDaoCassandraImpl extends CassandraBaseDao<ApplicationConfigEntity> implements ApplicationConfigDao {
+ private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static final Mapper<ApplicationConfigEntity> mapper = noSqlDb.getMappingManager().mapper(ApplicationConfigEntity.class);
+ private static final ApplicationConfigAccessor accessor = noSqlDb.getMappingManager().createAccessor(ApplicationConfigAccessor.class);
-public class ApplicationConfigDaoCassandraImpl extends CassandraBaseDao<ApplicationConfigEntity>
- implements
- ApplicationConfigDao {
-
- private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static final Mapper<ApplicationConfigEntity> mapper =
- noSqlDb.getMappingManager().mapper(ApplicationConfigEntity.class);
- private static final ApplicationConfigAccessor accessor =
- noSqlDb.getMappingManager().createAccessor(ApplicationConfigAccessor.class);
-
- @Override
- protected Mapper<ApplicationConfigEntity> getMapper() {
- return mapper;
- }
-
- @Override
- protected Object[] getKeys(ApplicationConfigEntity entity) {
- return new Object[]{entity.getNamespace(), entity.getKey(), entity.getValue()};
- }
-
- @Override
- public void create(ApplicationConfigEntity entity) {
- accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue());
- }
-
- @Override
- public void update(ApplicationConfigEntity entity) {
- accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue());
- }
-
- @Override
- public ApplicationConfigEntity get(ApplicationConfigEntity entity) {
- return accessor.get(entity.getNamespace(), entity.getKey());
- }
-
- @Override
- public Collection<ApplicationConfigEntity> list(ApplicationConfigEntity entity) {
- return accessor.list(entity.getNamespace()).all();
- }
-
- @Override
- public long getValueTimestamp(String namespace, String key) {
- ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key);
-
- return resultSet.one().getLong("writetime(value)");
- }
-
- @Override
- public ConfigurationData getConfigurationData(String namespace, String key) {
- //String value = accessor.getValue(namespace, key).one().getString("value");
- ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key);
- Row one = resultSet.one();
-
- if (Objects.nonNull(one)) {
- return new ConfigurationData(one.getString("value"), one.getLong("writetime(value)"));
+ @Override
+ protected Mapper<ApplicationConfigEntity> getMapper() {
+ return mapper;
}
- return null;
- }
+ @Override
+ protected Object[] getKeys(ApplicationConfigEntity entity) {
+ return new Object[]{entity.getNamespace(), entity.getKey(), entity.getValue()};
+ }
+ @Override
+ public void create(ApplicationConfigEntity entity) {
+ accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue());
+ }
- @Accessor
- interface ApplicationConfigAccessor {
+ @Override
+ public void update(ApplicationConfigEntity entity) {
+ accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue());
+ }
- @Query("select namespace, key, value from application_config where namespace=?")
- Result<ApplicationConfigEntity> list(String namespace);
+ @Override
+ public ApplicationConfigEntity get(ApplicationConfigEntity entity) {
+ return accessor.get(entity.getNamespace(), entity.getKey());
+ }
- @Query("insert into application_config (namespace, key, value) values (?,?,?)")
- ResultSet updateApplicationConfigData(String namespace, String key, String value);
+ @Override
+ public Collection<ApplicationConfigEntity> list(ApplicationConfigEntity entity) {
+ return accessor.list(entity.getNamespace()).all();
+ }
+
+ @Override
+ public long getValueTimestamp(String namespace, String key) {
+ ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key);
+ return resultSet.one().getLong("writetime(value)");
+ }
+
+ @Override
+ public ConfigurationData getConfigurationData(String namespace, String key) {
+ //String value = accessor.getValue(namespace, key).one().getString("value");
+ ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key);
+ Row one = resultSet.one();
+ if (Objects.nonNull(one)) {
+ return new ConfigurationData(one.getString("value"), one.getLong("writetime(value)"));
+ }
+ return null;
+ }
+
+ @Accessor
+ interface ApplicationConfigAccessor {
- @Query("select namespace, key, value from application_config where namespace=? and key=?")
- ApplicationConfigEntity get(String namespace, String key);
+ @Query("select namespace, key, value from application_config where namespace=?")
+ Result<ApplicationConfigEntity> list(String namespace);
- @Query("select value, writetime(value) from application_config where namespace=? and key=?")
- ResultSet getValueAndTimestampOfConfigurationValue(String namespace, String key);
+ @Query("insert into application_config (namespace, key, value) values (?,?,?)")
+ ResultSet updateApplicationConfigData(String namespace, String key, String value);
- }
+ @Query("select namespace, key, value from application_config where namespace=? and key=?")
+ ApplicationConfigEntity get(String namespace, String key);
+
+ @Query("select value, writetime(value) from application_config where namespace=? and key=?")
+ ResultSet getValueAndTimestampOfConfigurationValue(String namespace, String key);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java
index 23dde63e18..28bee62f93 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,18 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.dao.impl;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory;
-
public class ApplicationConfigDaoFactoryImpl extends ApplicationConfigDaoFactory {
- private static final ApplicationConfigDao INSTANCE = new ApplicationConfigDaoCassandraImpl();
- @Override
- public ApplicationConfigDao createInterface() {
- return INSTANCE;
- }
+ private static final ApplicationConfigDao INSTANCE = new ApplicationConfigDaoCassandraImpl();
+
+ @Override
+ public ApplicationConfigDao createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java
index 64d7f1a31a..1a8ac63966 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,10 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.dao.type;
-
import com.datastax.driver.mapping.annotations.ClusteringColumn;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
@@ -36,9 +34,9 @@ import lombok.Setter;
@Table(keyspace = "dox", name = "application_config")
public class ApplicationConfigEntity {
- @PartitionKey
- private String namespace;
- @ClusteringColumn
- private String key;
- private String value;
+ @PartitionKey
+ private String namespace;
+ @ClusteringColumn
+ private String key;
+ private String value;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java
index eebd3320f0..100bf38483 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,19 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.impl;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory;
-
public class ApplicationConfigFactoryImpl extends ApplicationConfigFactory {
- private static final ApplicationConfig INSTANCE = new ApplicationConfigImpl();
+ private static final ApplicationConfig INSTANCE = new ApplicationConfigImpl();
- @Override
- public ApplicationConfig createInterface() {
- return INSTANCE;
- }
+ @Override
+ public ApplicationConfig createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java
index 16cd1bce17..42ea334d9c 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,9 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.impl;
+import java.util.Collection;
+import java.util.Objects;
import org.openecomp.core.utilities.applicationconfig.ApplicationConfig;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao;
import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory;
@@ -29,43 +30,31 @@ import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
-import java.util.Collection;
-import java.util.Objects;
-
public class ApplicationConfigImpl implements ApplicationConfig {
- private static final ApplicationConfigDao applicationConfigDao =
- ApplicationConfigDaoFactory.getInstance().createInterface();
- private static final String CONFIGURATION_SEARCH_ERROR = "CONFIGURATION_NOT_FOUND";
- private static final String CONFIGURATION_SEARCH_ERROR_MSG =
- "Configuration for namespace %s and key %s was not found";
-
- @Override
- public ConfigurationData getConfigurationData(String namespace, String key) {
- ConfigurationData configurationData = applicationConfigDao.getConfigurationData(namespace, key);
-
- if (Objects.isNull(configurationData)) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId(CONFIGURATION_SEARCH_ERROR)
- .withMessage(String.format(CONFIGURATION_SEARCH_ERROR_MSG, namespace, key))
- .build());
+ private static final ApplicationConfigDao applicationConfigDao = ApplicationConfigDaoFactory.getInstance().createInterface();
+ private static final String CONFIGURATION_SEARCH_ERROR = "CONFIGURATION_NOT_FOUND";
+ private static final String CONFIGURATION_SEARCH_ERROR_MSG = "Configuration for namespace %s and key %s was not found";
+
+ @Override
+ public ConfigurationData getConfigurationData(String namespace, String key) {
+ ConfigurationData configurationData = applicationConfigDao.getConfigurationData(namespace, key);
+ if (Objects.isNull(configurationData)) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(CONFIGURATION_SEARCH_ERROR)
+ .withMessage(String.format(CONFIGURATION_SEARCH_ERROR_MSG, namespace, key)).build());
+ }
+ return configurationData;
}
- return configurationData;
- }
-
- @Override
- public void insertValue(String namespace, String key, String value) {
- ApplicationConfigEntity applicationConfigEntity =
- new ApplicationConfigEntity(namespace, key, value);
- applicationConfigDao.create(applicationConfigEntity);
- }
+ @Override
+ public void insertValue(String namespace, String key, String value) {
+ ApplicationConfigEntity applicationConfigEntity = new ApplicationConfigEntity(namespace, key, value);
+ applicationConfigDao.create(applicationConfigEntity);
+ }
- @Override
- public Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace) {
- ApplicationConfigEntity applicationConfigEntity =
- new ApplicationConfigEntity(namespace, null, null);
- return applicationConfigDao.list(applicationConfigEntity);
- }
+ @Override
+ public Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace) {
+ ApplicationConfigEntity applicationConfigEntity = new ApplicationConfigEntity(namespace, null, null);
+ return applicationConfigDao.list(applicationConfigEntity);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java
index 6149fc6ce4..7663e42bb8 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.applicationconfig.type;
import lombok.AllArgsConstructor;
@@ -29,6 +28,6 @@ import lombok.Setter;
@AllArgsConstructor
public class ConfigurationData {
- private String value;
- private long timeStamp;
+ private String value;
+ private long timeStamp;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java
index 12956417dd..87da8fc6e4 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/api/AbstractFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,20 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.factory.api;
import org.openecomp.core.factory.impl.AbstractFactoryBase;
/**
- * This class provides generic implementation of an abstract factory. Components exposed as Java
- * interfaces should have their own concrete factories derived from the given class. This assures
- * code alignment and consistency across all Service Management components.
- * The class actually
- * uses singleton pattern to instantiate and reuse just one instance of a factory. Therefore, each
- * factory implementation has to be <i>thread-safe</i>.
- * In a general case, the hierarchy of
- * factory objects for an Java interface <tt>IUknown</tt> may look as follows:
+ * This class provides generic implementation of an abstract factory. Components exposed as Java interfaces should have their own concrete factories
+ * derived from the given class. This assures code alignment and consistency across all Service Management components. The class actually uses
+ * singleton pattern to instantiate and reuse just one instance of a factory. Therefore, each factory implementation has to be <i>thread-safe</i>. In
+ * a general case, the hierarchy of factory objects for an Java interface <tt>IUknown</tt> may look as follows:
* <pre>
* AbstractFactory&lt;IUnknown&gt;
* ^
@@ -42,12 +37,10 @@ import org.openecomp.core.factory.impl.AbstractFactoryBase;
* | |
* BaselineFactoryImpl CustomFactoryImpl
* </pre>
- * Where the classes responsibility is: <ul> <li>Abstract factory - common logic to retrieve the
- * implementation class name from a central repository.</li> <li>Concrete factory - abstract class
- * that only exposes to application layer the type specific API such as: <ul> <li><tt>public static
- * ConcreteFactory getInstance()</tt></li> </ul> <li>Baseline factory - out of the box
- * implementation of concrete factory (that can be replaced by a custom one depending on customer
- * needs) which actually implements method: <ul> <li><tt>public IUnknown createInterface()</tt></li>
+ * Where the classes responsibility is: <ul> <li>Abstract factory - common logic to retrieve the implementation class name from a central
+ * repository.</li> <li>Concrete factory - abstract class that only exposes to application layer the type specific API such as: <ul> <li><tt>public
+ * static ConcreteFactory getInstance()</tt></li> </ul> <li>Baseline factory - out of the box implementation of concrete factory (that can be replaced
+ * by a custom one depending on customer needs) which actually implements method: <ul> <li><tt>public IUnknown createInterface()</tt></li>
* </ul> </ul> The normal concrete factory class may look like:
* <pre>
* public abstract class ConcreteFactory extends AbstractFactory&lt;IUnknown&gt; {
@@ -64,18 +57,15 @@ import org.openecomp.core.factory.impl.AbstractFactoryBase;
*/
public abstract class AbstractFactory<I> extends AbstractFactoryBase {
-
- /**
- * Returns the interface implementor instance.
- * <b>Note</b>: It's up to the concrete factory to decide on the actual
- * implementation of the returned interface. Therefore, the call can get the
- * same instance per each call in case of singleton implementation or new
- * instance otherwise. However, the API consumer may not assume anything
- * regarding the underlying logic and has always go through the factory to
- * obtain the reference.
- *
- * @return Implementor of the exposed Java interface.
- */
- public abstract I createInterface();
-
+ /**
+ * Returns the interface implementor instance.
+ * <b>Note</b>: It's up to the concrete factory to decide on the actual
+ * implementation of the returned interface. Therefore, the call can get the same instance per each call in case of singleton implementation or
+ * new instance otherwise. However, the API consumer may not assume anything regarding the underlying logic and has always go through the factory
+ * to obtain the reference.
+ *
+ * @return Implementor of the exposed Java interface.
+ */
+ public abstract I createInterface();
} // End of class
+
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java
index 3a117ef063..41bfeab826 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/AbstractFactoryBase.java
@@ -13,30 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.factory.impl;
public abstract class AbstractFactoryBase {
- /**
- * Instantiates the configured implementation of an abstract factory.
- *
- * @param <F> Type specific abstract factory for concrete Java interface
- * @param factoryType Java class of type specific abstract factory
- * @return Instance of implementation class
- */
- public static <F extends AbstractFactoryBase> F getInstance(Class<F> factoryType) {
- return FactoryManager.getInstance().getFactoryInstance(factoryType);
- }
+ /**
+ * Instantiates the configured implementation of an abstract factory.
+ *
+ * @param <F> Type specific abstract factory for concrete Java interface
+ * @param factoryType Java class of type specific abstract factory
+ * @return Instance of implementation class
+ */
+ public static <F extends AbstractFactoryBase> F getInstance(Class<F> factoryType) {
+ return FactoryManager.getInstance().getFactoryInstance(factoryType);
+ }
+
+ protected void init() {
+ // allows custom initialization
- protected void init() {
- // allows custom initialization
- // noop by default
- }
+ // noop by default
+ }
- protected void stop() {
- // allows custom shutdown
- // noop by default
- }
+ protected void stop() {
+ // allows custom shutdown
+ // noop by default
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java
index ec2d93f35b..26816aaafe 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-api/src/main/java/org/openecomp/core/factory/impl/FactoryManager.java
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.factory.impl;
import com.amdocs.zusammen.utils.facade.impl.FactoryConfig;
@@ -33,9 +32,8 @@ public class FactoryManager {
private static final FactoryManager instance = new FactoryManager();
private static final String ERROR_CODE_E0001 = "E0001";
/**
- * Temporary registry of default implementations. The map keeps class names rather then class
- * types to allow unloading of those classes from memory by garbage collector if factory is not
- * actually used.
+ * Temporary registry of default implementations. The map keeps class names rather then class types to allow unloading of those classes from
+ * memory by garbage collector if factory is not actually used.
*/
private final Map<String, String> factoryRegistry = new ConcurrentHashMap<>();
/**
@@ -43,7 +41,6 @@ public class FactoryManager {
*/
private final Map<String, AbstractFactoryBase> factoryInstanceMap = new ConcurrentHashMap<>();
-
private FactoryManager() {
initializeFactoryRegistry();
}
@@ -54,17 +51,13 @@ public class FactoryManager {
private void initializeFactoryRegistry() {
final Map<String, String> factoryMap = FactoryConfig.getFactoriesMap();
-
for (final Map.Entry<String, String> entry : factoryMap.entrySet()) {
final String abstractClassName = entry.getKey();
final String concreteTypeName = entry.getValue();
-
if (StringUtils.isEmpty(concreteTypeName)) {
throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withId("E0003")
- .withMessage("Missing configuration value:" + concreteTypeName + ".")
+ new ErrorCode.ErrorCodeBuilder().withId("E0003").withMessage("Missing configuration value:" + concreteTypeName + ".")
.withCategory(ErrorCategory.SYSTEM).build());
-
}
registerFactory(abstractClassName, concreteTypeName);
}
@@ -80,32 +73,26 @@ public class FactoryManager {
@SuppressWarnings("unchecked")
public <F extends AbstractFactoryBase> F getFactoryInstance(Class<F> factoryType) {
if (factoryType == null) {
- throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001)
- .withMessage("Mandatory input factory type.").withCategory(ErrorCategory.SYSTEM)
- .build());
-
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory type.")
+ .withCategory(ErrorCategory.SYSTEM).build());
}
final String factoryTypeName = factoryType.getName();
// Check if the factory is already cached
if (factoryInstanceMap.get(factoryTypeName) == null) {
//if not, create a new one and cache it
+
// Get the implementation class name
final String implName = factoryRegistry.get(factoryTypeName);
-
if (StringUtils.isEmpty(implName)) {
throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001)
- .withMessage("Mandatory input factory implementation.")
+ new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory implementation.")
.withCategory(ErrorCategory.SYSTEM).build());
}
-
F factory = CommonMethods.newInstance(implName, factoryType);
factory.init();
// Cache the instantiated singleton
factoryInstanceMap.putIfAbsent(factoryTypeName, factory);
}
-
return (F) factoryInstanceMap.get(factoryTypeName);
}
@@ -115,6 +102,7 @@ public class FactoryManager {
/**
* Unregister factory and removes the cached instance if any.
+ *
* @param factoryName the factory name to unregister
*/
public void unregisterFactory(final String factoryName) {
@@ -134,10 +122,9 @@ public class FactoryManager {
public <F extends AbstractFactoryBase> void removeFactoryInstance(Class<F> factory) {
if (factory == null) {
throw new CoreException(
- new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory.")
- .withCategory(ErrorCategory.SYSTEM).build());
+ new ErrorCode.ErrorCodeBuilder().withId(ERROR_CODE_E0001).withMessage("Mandatory input factory.").withCategory(ErrorCategory.SYSTEM)
+ .build());
}
-
factoryInstanceMap.remove(factory.getName());
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java
index f4e1a85fee..a98ba44cf9 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/AbstractContextFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,11 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.factory;
import org.openecomp.core.factory.impl.AbstractFactoryBase;
public abstract class AbstractContextFactory<I, C> extends AbstractFactoryBase {
- public abstract I createInterface(C contextType);
+
+ public abstract I createInterface(C contextType);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java
index 31df923bdd..cfe50f1619 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoriesConfigImpl.java
@@ -13,45 +13,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.factory;
-
-import org.openecomp.core.factory.api.FactoriesConfiguration;
-import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.sdc.common.errors.SdcConfigurationException;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.openecomp.core.factory.api.FactoriesConfiguration;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.sdc.common.errors.SdcConfigurationException;
public final class FactoriesConfigImpl implements FactoriesConfiguration {
- private final Map factoryConfigurationMap = new HashMap();
+ private final Map factoryConfigurationMap = new HashMap();
- public FactoriesConfigImpl() {
- init();
- }
+ public FactoriesConfigImpl() {
+ init();
+ }
- @SuppressWarnings("unchecked")
- @Override
- public Map<String, String> getFactoriesMap() {
- return factoryConfigurationMap;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map<String, String> getFactoriesMap() {
+ return factoryConfigurationMap;
+ }
- private void init() {
- final List<URL> factoryConfigUrlList = FileUtils.getAllLocations("factoryConfiguration.json");
- for (final URL factoryConfigUrl : factoryConfigUrlList) {
- try (InputStream stream = factoryConfigUrl.openStream()) {
- factoryConfigurationMap.putAll(JsonUtil.json2Object(stream, Map.class));
- } catch (final IOException e) {
- throw new SdcConfigurationException("Failed to initialize Factory from '" + factoryConfigUrl.getPath() +"'", e);
- }
+ private void init() {
+ final List<URL> factoryConfigUrlList = FileUtils.getAllLocations("factoryConfiguration.json");
+ for (final URL factoryConfigUrl : factoryConfigUrlList) {
+ try (InputStream stream = factoryConfigUrl.openStream()) {
+ factoryConfigurationMap.putAll(JsonUtil.json2Object(stream, Map.class));
+ } catch (final IOException e) {
+ throw new SdcConfigurationException("Failed to initialize Factory from '" + factoryConfigUrl.getPath() + "'", e);
+ }
+ }
}
- }
}
-
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java
index 7dbf921ebf..0c118fc2c9 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/FactoryConfig.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.factory;
import java.util.Map;
@@ -26,14 +25,13 @@ import org.openecomp.core.utilities.CommonMethods;
public final class FactoryConfig {
- private static final FactoriesConfiguration INSTANCE = CommonMethods.newInstance(
- "org.openecomp.core.factory.FactoriesConfigImpl", FactoriesConfiguration.class);
-
- private FactoryConfig() {
+ private static final FactoriesConfiguration INSTANCE = CommonMethods
+ .newInstance("org.openecomp.core.factory.FactoriesConfigImpl", FactoriesConfiguration.class);
- }
+ private FactoryConfig() {
+ }
- public static Map<String, String> getFactoriesMap() {
- return INSTANCE.getFactoriesMap();
- }
+ public static Map<String, String> getFactoriesMap() {
+ return INSTANCE.getFactoriesMap();
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java
index 3de0d88f43..0a091c1864 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/AbstractComponentFactory.java
@@ -4,17 +4,17 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.factory.api;
public abstract class AbstractComponentFactory<I> extends AbstractFactory<I> {
+
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java
index 8086181204..b1da7950ce 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-facade-lib/openecomp-facade-core/src/main/java/org/openecomp/core/factory/api/FactoriesConfiguration.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,13 +17,11 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.factory.api;
import java.util.Map;
-
public interface FactoriesConfiguration {
- Map<String, String> getFactoriesMap();
+ Map<String, String> getFactoriesMap();
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
index fa23b51742..e46cade267 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/BaseDao.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import java.util.Collection;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
index 36dfefa840..02db64ec66 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDao.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import org.openecomp.core.dao.types.UniqueValueEntity;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
index 022ad8e09d..c653c8dc4f 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/UniqueValueDaoFactory.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao;
import org.openecomp.core.factory.api.AbstractComponentFactory;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
index 24038b9b0c..d107c9f388 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/dao/types/UniqueValueEntity.java
@@ -17,12 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao.types;
import com.datastax.driver.mapping.annotations.PartitionKey;
import com.datastax.driver.mapping.annotations.Table;
-
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -37,7 +35,6 @@ public class UniqueValueEntity {
@PartitionKey
private String type;
-
@PartitionKey(value = 1)
private String value;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
index ff4661c44d..844ce88265 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/api/NoSqlDb.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.api;
import com.datastax.driver.core.ResultSet;
@@ -26,7 +25,6 @@ import com.datastax.driver.mapping.MappingManager;
public interface NoSqlDb {
//TODO: remove cassandra types from here!! (like done in SDC...).
-
void insert(String tableName, String[] colNames, Object[] values);
ResultSet execute(String statement);
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
index 31b6f6a505..e86b64e1aa 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/nosqldb/factory/NoSqlDbFactory.java
@@ -17,18 +17,15 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.factory;
import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
import org.openecomp.core.nosqldb.api.NoSqlDb;
-
public abstract class NoSqlDbFactory extends AbstractComponentFactory<NoSqlDb> {
public static NoSqlDbFactory getInstance() {
-
return AbstractFactory.getInstance(NoSqlDbFactory.class);
}
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
index aded1fa99f..a70bc47864 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/main/java/org/openecomp/core/util/UniqueValueUtil.java
@@ -13,11 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.util;
import java.util.Optional;
-
import org.apache.commons.lang3.ArrayUtils;
import org.openecomp.core.dao.UniqueValueDao;
import org.openecomp.core.dao.types.UniqueValueEntity;
@@ -31,13 +29,24 @@ public class UniqueValueUtil {
private static final String UNIQUE_VALUE_VIOLATION = "UNIQUE_VALUE_VIOLATION";
private static final String UNIQUE_VALUE_VIOLATION_MSG = "%s with the value '%s' already exists.";
private static final char FORMATTED_UNIQUE_VALUE_SEPARATOR = '_';
-
private final UniqueValueDao uniqueValueDao;
public UniqueValueUtil(UniqueValueDao uniqueValueDao) {
this.uniqueValueDao = uniqueValueDao;
}
+ private static Optional<String> formatValue(String[] uniqueCombination) {
+ if (uniqueCombination == null || uniqueCombination.length == 0 || getValueWithoutContext(uniqueCombination) == null) {
+ return Optional.empty();
+ }
+ uniqueCombination[uniqueCombination.length - 1] = getValueWithoutContext(uniqueCombination).toLowerCase();
+ return Optional.of(CommonMethods.arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
+ }
+
+ private static String getValueWithoutContext(String... uniqueCombination) {
+ return uniqueCombination[uniqueCombination.length - 1];
+ }
+
/**
* Create unique value.
*
@@ -49,7 +58,6 @@ public class UniqueValueUtil {
if (ArrayUtils.isNotEmpty(uniqueCombination)) {
originalEntityName = uniqueCombination[uniqueCombination.length - 1];
}
-
Optional<String> formattedValue = formatValue(uniqueCombination);
if (formattedValue.isPresent()) {
validateUniqueValue(type, formattedValue.get(), originalEntityName);
@@ -64,9 +72,7 @@ public class UniqueValueUtil {
* @param uniqueCombination the unique combination
*/
public void deleteUniqueValue(String type, String... uniqueCombination) {
- formatValue(uniqueCombination).ifPresent(
- formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
-
+ formatValue(uniqueCombination).ifPresent(formattedValue -> uniqueValueDao.delete(new UniqueValueEntity(type, formattedValue)));
}
/**
@@ -77,11 +83,10 @@ public class UniqueValueUtil {
* @param newValue the new value
* @param uniqueContext the unique context
*/
- public void updateUniqueValue(String type, String oldValue, String newValue,
- String... uniqueContext) {
+ public void updateUniqueValue(String type, String oldValue, String newValue, String... uniqueContext) {
if (newValue == null || !newValue.equalsIgnoreCase(oldValue)) {
- createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {newValue}));
- deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[] {oldValue}));
+ createUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{newValue}));
+ deleteUniqueValue(type, CommonMethods.concat(uniqueContext, new String[]{oldValue}));
}
}
@@ -96,7 +101,6 @@ public class UniqueValueUtil {
if (ArrayUtils.isNotEmpty(uniqueCombination)) {
originalEntityName = uniqueCombination[uniqueCombination.length - 1];
}
-
Optional<String> formattedValue = formatValue(uniqueCombination);
if (formattedValue.isPresent()) {
validateUniqueValue(type, formattedValue.get(), originalEntityName);
@@ -105,12 +109,8 @@ public class UniqueValueUtil {
private void validateUniqueValue(String type, String formattedValue, String originalEntityName) {
if (isUniqueValueOccupied(type, formattedValue)) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId(UNIQUE_VALUE_VIOLATION)
- .withMessage(String
- .format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName))
- .build());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(UNIQUE_VALUE_VIOLATION)
+ .withMessage(String.format(UNIQUE_VALUE_VIOLATION_MSG, type, originalEntityName)).build());
}
}
@@ -120,28 +120,10 @@ public class UniqueValueUtil {
* @return true if the unique value is occupied, false otherwise
*/
public boolean isUniqueValueOccupied(String type, String... uniqueCombination) {
- return formatValue(uniqueCombination)
- .map(formattedValue -> isUniqueValueOccupied(type, formattedValue))
- .orElse(false);
+ return formatValue(uniqueCombination).map(formattedValue -> isUniqueValueOccupied(type, formattedValue)).orElse(false);
}
private boolean isUniqueValueOccupied(String type, String formattedValue) {
return uniqueValueDao.get(new UniqueValueEntity(type, formattedValue)) != null;
}
-
- private static Optional<String> formatValue(String[] uniqueCombination) {
- if (uniqueCombination == null || uniqueCombination.length == 0
- || getValueWithoutContext(uniqueCombination) == null) {
- return Optional.empty();
- }
-
- uniqueCombination[uniqueCombination.length - 1] =
- getValueWithoutContext(uniqueCombination).toLowerCase();
- return Optional.of(CommonMethods
- .arrayToSeparatedString(uniqueCombination, FORMATTED_UNIQUE_VALUE_SEPARATOR));
- }
-
- private static String getValueWithoutContext(String... uniqueCombination) {
- return uniqueCombination[uniqueCombination.length - 1];
- }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/CassandraBaseDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/CassandraBaseDao.java
index 1b3dbc4c6f..6205622cea 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/CassandraBaseDao.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/CassandraBaseDao.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,34 +17,34 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao.impl;
import com.datastax.driver.mapping.Mapper;
import org.openecomp.core.dao.BaseDao;
public abstract class CassandraBaseDao<T> implements BaseDao<T> {
- protected abstract Mapper<T> getMapper();
- protected abstract Object[] getKeys(T entity);
+ protected abstract Mapper<T> getMapper();
+
+ protected abstract Object[] getKeys(T entity);
- @Override
- public void create(T entity) {
- getMapper().save(entity);
- }
+ @Override
+ public void create(T entity) {
+ getMapper().save(entity);
+ }
- @Override
- public void update(T entity) {
- getMapper().save(entity);
- }
+ @Override
+ public void update(T entity) {
+ getMapper().save(entity);
+ }
- @Override
- public T get(T entity) {
- return getMapper().get(getKeys(entity));
- }
+ @Override
+ public T get(T entity) {
+ return getMapper().get(getKeys(entity));
+ }
- @Override
- public void delete(T entity) {
- getMapper().delete(entity);
- }
+ @Override
+ public void delete(T entity) {
+ getMapper().delete(entity);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueCassandraDaoImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueCassandraDaoImpl.java
index a2f34bd329..b80050b370 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueCassandraDaoImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueCassandraDaoImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,49 +17,43 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao.impl;
import com.datastax.driver.mapping.Mapper;
import com.datastax.driver.mapping.Result;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;
+import java.util.Collection;
import org.openecomp.core.dao.UniqueValueDao;
import org.openecomp.core.dao.types.UniqueValueEntity;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
-import java.util.Collection;
-
-public class UniqueValueCassandraDaoImpl extends CassandraBaseDao<UniqueValueEntity> implements
- UniqueValueDao {
-
- private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static Mapper<UniqueValueEntity> mapper =
- noSqlDb.getMappingManager().mapper(UniqueValueEntity.class);
- private static UniqueValueAccessor accessor =
- noSqlDb.getMappingManager().createAccessor(UniqueValueAccessor.class);
+public class UniqueValueCassandraDaoImpl extends CassandraBaseDao<UniqueValueEntity> implements UniqueValueDao {
+ private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static Mapper<UniqueValueEntity> mapper = noSqlDb.getMappingManager().mapper(UniqueValueEntity.class);
+ private static UniqueValueAccessor accessor = noSqlDb.getMappingManager().createAccessor(UniqueValueAccessor.class);
- @Override
- protected Mapper<UniqueValueEntity> getMapper() {
- return mapper;
- }
+ @Override
+ protected Mapper<UniqueValueEntity> getMapper() {
+ return mapper;
+ }
- @Override
- protected Object[] getKeys(UniqueValueEntity entity) {
- return new Object[]{entity.getType(), entity.getValue()};
- }
+ @Override
+ protected Object[] getKeys(UniqueValueEntity entity) {
+ return new Object[]{entity.getType(), entity.getValue()};
+ }
- @Override
- public Collection<UniqueValueEntity> list(UniqueValueEntity entity) {
- return accessor.listAll().all();
- }
+ @Override
+ public Collection<UniqueValueEntity> list(UniqueValueEntity entity) {
+ return accessor.listAll().all();
+ }
- @Accessor
- interface UniqueValueAccessor {
+ @Accessor
+ interface UniqueValueAccessor {
- @Query("select * from unique_value")
- Result<UniqueValueEntity> listAll();
- }
+ @Query("select * from unique_value")
+ Result<UniqueValueEntity> listAll();
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueDaoFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueDaoFactoryImpl.java
index ac47de9b20..36c0b208c8 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/dao/impl/UniqueValueDaoFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,17 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.dao.impl;
import org.openecomp.core.dao.UniqueValueDao;
import org.openecomp.core.dao.UniqueValueDaoFactory;
public class UniqueValueDaoFactoryImpl extends UniqueValueDaoFactory {
- private static UniqueValueDao instance = new UniqueValueCassandraDaoImpl();
- @Override
- public UniqueValueDao createInterface() {
- return instance;
- }
+ private static UniqueValueDao instance = new UniqueValueCassandraDaoImpl();
+
+ @Override
+ public UniqueValueDao createInterface() {
+ return instance;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbFactoryImpl.java
index 134d341d05..b62689d955 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,28 +17,25 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.impl.cassandra;
-
import com.datastax.driver.core.Session;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
public class CassandraNoSqlDbFactoryImpl extends NoSqlDbFactory {
- @Override
- public NoSqlDb createInterface() {
-
+ @Override
+ public NoSqlDb createInterface() {
+ return new CassandraNoSqlDbImpl(ReferenceHolder.CASSANDRA);
+ }
- return new CassandraNoSqlDbImpl(ReferenceHolder.CASSANDRA);
- }
+ protected void stop() {
+ ReferenceHolder.CASSANDRA.close();
+ }
- protected void stop() {
- ReferenceHolder.CASSANDRA.close();
- }
+ private static class ReferenceHolder {
- private static class ReferenceHolder {
- private static final Session CASSANDRA = CassandraSessionFactory.getSession();
- }
+ private static final Session CASSANDRA = CassandraSessionFactory.getSession();
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java
index 539fbcd92f..237c48d013 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraNoSqlDbImpl.java
@@ -12,18 +12,17 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-*/
-
+ */
package org.openecomp.core.nosqldb.impl.cassandra;
-import com.datastax.driver.mapping.MappingManager;
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.Host;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
-
-
+import com.datastax.driver.mapping.MappingManager;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.util.CassandraUtils;
import org.openecomp.core.utilities.CommonMethods;
@@ -33,49 +32,34 @@ import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import java.util.Set;
-import java.util.stream.Collectors;
-
class CassandraNoSqlDbImpl implements NoSqlDb {
private final Session session;
private final String keySpace;
private final MappingManager mappingManager;
-
private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
-
public CassandraNoSqlDbImpl(Session session) {
this.session = session;
this.keySpace = this.session.getLoggedKeyspace();
this.mappingManager = new MappingManager(this.session);
-
}
@Override
public void insert(String tableName, String[] colNames, Object[] values) {
if (colNames.length != values.length) {
- throw new CoreException((new ErrorCode.ErrorCodeBuilder()).withMessage(
- "number of colmuns[" + colNames.length + "] is not equal to the number of values["
- + values.length + "].").withId("E0005").withCategory(ErrorCategory.APPLICATION)
- .build());
+ throw new CoreException((new ErrorCode.ErrorCodeBuilder())
+ .withMessage("number of colmuns[" + colNames.length + "] is not equal to the number of values[" + values.length + "].")
+ .withId("E0005").withCategory(ErrorCategory.APPLICATION).build());
}
-
StringBuilder sb = new StringBuilder();
- sb.append("insert into ")
- .append(tableName)
- .append(" (")
- .append(CommonMethods.arrayToCommaSeparatedString(colNames))
- .append(") values (")
- .append(CommonMethods.duplicateStringWithDelimiter("?", ',', values.length))
- .append(")");
+ sb.append("insert into ").append(tableName).append(" (").append(CommonMethods.arrayToCommaSeparatedString(colNames)).append(") values (")
+ .append(CommonMethods.duplicateStringWithDelimiter("?", ',', values.length)).append(")");
log.info(sb.toString());
PreparedStatement prepared = session.prepare(sb.toString());
-
BoundStatement bound;
bound = prepared.bind(values);
session.execute(bound);
-
}
@Override
@@ -85,21 +69,18 @@ class CassandraNoSqlDbImpl implements NoSqlDb {
@Override
public ResultSet execute(String statementName, Object... values) {
-
String statement = CassandraUtils.getStatement(statementName);
if (statement == null) {
statement = statementName;
}
if (values != null) {
PreparedStatement prepared = session.prepare(statement);
-
BoundStatement bound;
bound = prepared.bind(values);
return session.execute(bound);
} else {
return session.execute(statement);
}
-
}
@Override
@@ -111,10 +92,9 @@ class CassandraNoSqlDbImpl implements NoSqlDb {
public String getVersion() {
try {
Set<Host> allHosts = this.session.getCluster().getMetadata().getAllHosts();
- Set<String> versions = allHosts.stream().map(host -> host.getCassandraVersion().toString())
- .collect(Collectors.toSet());
+ Set<String> versions = allHosts.stream().map(host -> host.getCassandraVersion().toString()).collect(Collectors.toSet());
return versions.stream().collect(Collectors.joining(","));
- } catch (Exception e){
+ } catch (Exception e) {
log.error("Failed to retrieve version", e);
return "Failed to retrieve version";
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
index a507017888..8f3d51d618 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/impl/cassandra/CassandraSessionFactory.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.nosqldb.impl.cassandra;
import com.datastax.driver.core.Cluster;
@@ -22,22 +21,23 @@ import com.datastax.driver.core.QueryOptions;
import com.datastax.driver.core.RemoteEndpointAwareJdkSSLOptions;
import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.Session;
-
-
-import com.datastax.driver.core.policies.*;
-import org.openecomp.core.nosqldb.util.CassandraUtils;
-import org.openecomp.sdc.common.errors.SdcConfigurationException;
-import org.openecomp.sdc.common.session.SessionContextProviderFactory;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.TrustManagerFactory;
+import com.datastax.driver.core.policies.ConstantReconnectionPolicy;
+import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
+import com.datastax.driver.core.policies.DefaultRetryPolicy;
+import com.datastax.driver.core.policies.LoadBalancingPolicy;
+import com.datastax.driver.core.policies.TokenAwarePolicy;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.Objects;
import java.util.Optional;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+import org.openecomp.core.nosqldb.util.CassandraUtils;
+import org.openecomp.sdc.common.errors.SdcConfigurationException;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
public class CassandraSessionFactory {
@@ -60,57 +60,42 @@ public class CassandraSessionFactory {
String[] addresses = CassandraUtils.getAddresses();
int cassandraPort = CassandraUtils.getCassandraPort();
Long reconnectTimeout = CassandraUtils.getReconnectTimeout();
-
Cluster.Builder builder = Cluster.builder();
-
- if(null != reconnectTimeout) {
- builder.withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout))
- .withRetryPolicy(DefaultRetryPolicy.INSTANCE);
+ if (null != reconnectTimeout) {
+ builder.withReconnectionPolicy(new ConstantReconnectionPolicy(reconnectTimeout)).withRetryPolicy(DefaultRetryPolicy.INSTANCE);
}
-
builder.withPort(cassandraPort);
-
for (String address : addresses) {
builder.addContactPoint(address);
}
-
//Check if ssl
Boolean isSsl = CassandraUtils.isSsl();
if (isSsl) {
builder.withSSL(getSslOptions());
}
-
//Check if user/pass
Boolean isAuthenticate = CassandraUtils.isAuthenticate();
if (isAuthenticate) {
builder.withCredentials(CassandraUtils.getUser(), CassandraUtils.getPassword());
}
-
setConsistencyLevel(builder, addresses);
-
setLocalDataCenter(builder);
-
Cluster cluster = builder.build();
- String keyStore = SessionContextProviderFactory.getInstance().createInterface().get()
- .getTenant();
- LOGGER.info("Cassandra client created hosts: {} port: {} SSL enabled: {} reconnectTimeout",
- addresses, cassandraPort, isSsl, reconnectTimeout);
+ String keyStore = SessionContextProviderFactory.getInstance().createInterface().get().getTenant();
+ LOGGER
+ .info("Cassandra client created hosts: {} port: {} SSL enabled: {} reconnectTimeout", addresses, cassandraPort, isSsl, reconnectTimeout);
return cluster.connect(keyStore);
}
private static void setLocalDataCenter(Cluster.Builder builder) {
String localDataCenter = CassandraUtils.getLocalDataCenter();
if (Objects.nonNull(localDataCenter)) {
- LOGGER.info("localDatacenter was provided, setting Cassndra client to use datacenter: {} as local.",
- localDataCenter);
-
- LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(
- DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
+ LOGGER.info("localDatacenter was provided, setting Cassndra client to use datacenter: {} as local.", localDataCenter);
+ LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
builder.withLoadBalancingPolicy(tokenAwarePolicy);
} else {
- LOGGER.info(
- "localDatacenter was provided, the driver will use the datacenter of the first contact " +
- "point that was reached at initialization");
+ LOGGER.info("localDatacenter was provided, the driver will use the datacenter of the first contact "
+ + "point that was reached at initialization");
}
}
@@ -118,54 +103,42 @@ public class CassandraSessionFactory {
if (addresses != null && addresses.length > 1) {
String consistencyLevel = CassandraUtils.getConsistencyLevel();
if (Objects.nonNull(consistencyLevel)) {
- LOGGER.info(
- "consistencyLevel was provided, setting Cassandra client to use consistencyLevel: {}" +
- " as "
- , consistencyLevel);
- builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf
- (consistencyLevel)));
+ LOGGER.info("consistencyLevel was provided, setting Cassandra client to use consistencyLevel: {}" + " as ", consistencyLevel);
+ builder.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel)));
}
}
}
private static SSLOptions getSslOptions() {
-
Optional<String> trustStorePath = Optional.ofNullable(CassandraUtils.getTruststore());
if (!trustStorePath.isPresent()) {
throw new SdcConfigurationException("Missing configuration for Cassandra trustStorePath");
}
-
Optional<String> trustStorePassword = Optional.ofNullable(CassandraUtils.getTruststorePassword());
if (!trustStorePassword.isPresent()) {
throw new SdcConfigurationException("Missing configuration for Cassandra trustStorePassword");
}
-
SSLContext context = getSslContext(trustStorePath.get(), trustStorePassword.get());
String[] css = new String[]{"TLS_RSA_WITH_AES_128_CBC_SHA"};
return RemoteEndpointAwareJdkSSLOptions.builder().withSSLContext(context).withCipherSuites(css).build();
}
private static SSLContext getSslContext(String truststorePath, String trustStorePassword) {
-
try (FileInputStream tsf = new FileInputStream(truststorePath)) {
-
SSLContext ctx = SSLContext.getInstance("TLS");
-
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(tsf, trustStorePassword.toCharArray());
- TrustManagerFactory tmf =
- TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
-
ctx.init(null, tmf.getTrustManagers(), new SecureRandom());
return ctx;
-
} catch (Exception exception) {
throw new SdcConfigurationException("Failed to get SSL Contexts for Cassandra connection", exception);
}
}
private static class ReferenceHolder {
+
private static final Session CASSANDRA = newCassandraSession();
private ReferenceHolder() {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
index 30bc0a72a3..d6840fedd1 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/CassandraUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,90 +17,76 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.util;
-import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.core.utilities.json.JsonUtil;
-
import java.util.HashMap;
import java.util.Map;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
public class CassandraUtils {
+ private static final String CASSANDRA_STATEMENT_DEFINITION_FILE = "cassandraStatements.json";
+ private static Map<String, String> statementMap = new HashMap<>();
- private static final String CASSANDRA_STATEMENT_DEFINITION_FILE = "cassandraStatements.json";
- private static Map<String, String> statementMap = new HashMap<>();
-
- public static String[] getAddresses() {
- return ConfigurationManager.getInstance().getAddresses();
- }
-
- public static Long getReconnectTimeout() {
- return ConfigurationManager.getInstance().getReconnectTimeout();
- }
-
- public static String getKeySpace() {
- return ConfigurationManager.getInstance().getKeySpace();
- }
-
- /**
- * Gets statement.
- *
- * @param statementName the statement name
- * @return the statement
- */
- public static String getStatement(String statementName) {
-
- if (statementMap.size() == 0) {
- statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE,
- stream -> JsonUtil.json2Object(stream, Map.class));
+ public static String[] getAddresses() {
+ return ConfigurationManager.getInstance().getAddresses();
}
- return statementMap.get(statementName);
- }
-
- public static String getUser() {
-
- return ConfigurationManager.getInstance().getUsername();
- }
-
- public static String getPassword() {
- return ConfigurationManager.getInstance().getPassword();
-
- }
-
- public static String getTruststore() {
- return ConfigurationManager.getInstance().getTruststorePath();
-
- }
+ public static Long getReconnectTimeout() {
+ return ConfigurationManager.getInstance().getReconnectTimeout();
+ }
- public static String getTruststorePassword() {
- return ConfigurationManager.getInstance().getTruststorePassword();
+ public static String getKeySpace() {
+ return ConfigurationManager.getInstance().getKeySpace();
+ }
- }
+ /**
+ * Gets statement.
+ *
+ * @param statementName the statement name
+ * @return the statement
+ */
+ public static String getStatement(String statementName) {
+ if (statementMap.size() == 0) {
+ statementMap = FileUtils.readViaInputStream(CASSANDRA_STATEMENT_DEFINITION_FILE, stream -> JsonUtil.json2Object(stream, Map.class));
+ }
+ return statementMap.get(statementName);
+ }
- public static int getCassandraPort() {
- return ConfigurationManager.getInstance().getCassandraPort();
+ public static String getUser() {
+ return ConfigurationManager.getInstance().getUsername();
+ }
- }
+ public static String getPassword() {
+ return ConfigurationManager.getInstance().getPassword();
+ }
- public static boolean isSsl() {
- return ConfigurationManager.getInstance().isSsl();
+ public static String getTruststore() {
+ return ConfigurationManager.getInstance().getTruststorePath();
+ }
- }
+ public static String getTruststorePassword() {
+ return ConfigurationManager.getInstance().getTruststorePassword();
+ }
- public static boolean isAuthenticate() {
- return ConfigurationManager.getInstance().isAuthenticate();
- }
+ public static int getCassandraPort() {
+ return ConfigurationManager.getInstance().getCassandraPort();
+ }
- public static String getConsistencyLevel() {
+ public static boolean isSsl() {
+ return ConfigurationManager.getInstance().isSsl();
+ }
- return ConfigurationManager.getInstance().getConsistencyLevel();
+ public static boolean isAuthenticate() {
+ return ConfigurationManager.getInstance().isAuthenticate();
+ }
- }
+ public static String getConsistencyLevel() {
+ return ConfigurationManager.getInstance().getConsistencyLevel();
+ }
- public static String getLocalDataCenter() {
- return ConfigurationManager.getInstance().getLocalDataCenter();
- }
+ public static String getLocalDataCenter() {
+ return ConfigurationManager.getInstance().getLocalDataCenter();
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
index a1d5246eee..666901edfe 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-core/src/main/java/org/openecomp/core/nosqldb/util/ConfigurationManager.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,15 +17,8 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.nosqldb.util;
-import org.apache.commons.collections4.CollectionUtils;
-import org.onap.sdc.tosca.services.YamlUtil;
-import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -35,248 +28,241 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
+import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.services.YamlUtil;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
/**
* The type Configuration manager.
*/
public class ConfigurationManager {
- static final String CONFIGURATION_YAML_FILE = "configuration.yaml";
- static private final Integer DEFAULT_CASSANDRA_PORT = 9042;
- private static final String CASSANDRA = "cassandra";
- private static final String CASSANDRA_KEY = CASSANDRA + "Config";
- private static final String DEFAULT_KEYSPACE_NAME = "dox";
- private static final String CASSANDRA_ADDRESSES = CASSANDRA + ".addresses";
- private static final String CASSANDRA_DOX_KEY_STORE = CASSANDRA + ".dox.keystore";
- private static final String CASSANDRA_AUTHENTICATE = CASSANDRA + ".authenticate";
- private static final String CASSANDRA_USER = CASSANDRA + ".user";
- private static final String CASSANDRA_PASSWORD = CASSANDRA + ".password";
- private static final String CASSANDRA_SSL = CASSANDRA + ".ssl";
- private static final String CASSANDRA_TRUSTSTORE = CASSANDRA + ".Truststore";
- private static final String CASSANDRA_TRUSTSTORE_PASSWORD = CASSANDRA + ".TruststorePassword";
- private static final String CASSANDRA_HOSTS_KEY = CASSANDRA + "Hosts";
- private static final String CASSANDRA_PORT_KEY = "cassandraPort";
- private static final String CASSANDRA_USERNAME_KEY = "username";
- private static final String CASSANDRA_RECONNECT_TIMEOUT = "reconnectTimeout";
- @SuppressWarnings("squid:S2068")
- private static final String CASSANDRA_PASSWORD_KEY = "password";
- private static final String CASSANDRA_AUTHENTICATE_KEY = "authenticate";
- private static final String CASSANDRA_SSL_KEY = "ssl";
- private static final String CASSANDRA_TRUSTSTORE_PATH_KEY = "truststorePath";
- @SuppressWarnings("squid:S2068")
- private static final String CASSANDRA_TRUSTSTORE_PASSWORD_KEY = "truststorePassword";
- private static final String CONSISTENCY_LEVEL = CASSANDRA + ".consistencyLevel";
- private static final String CONSISTENCY_LEVEL_KEY = "consistencyLevel";
- private static final String LOCAL_DATA_CENTER_KEY = "localDataCenter";
- private static final String LOCAL_DATA_CENTER = CASSANDRA + ".localDataCenter";
- private static ConfigurationManager instance = null;
- private final LinkedHashMap<String, Object> cassandraConfiguration;
-
- private static final Logger LOG = LoggerFactory.getLogger(ConfigurationManager.class);
-
-
- private ConfigurationManager() {
-
- String configurationYamlFile = System.getProperty(CONFIGURATION_YAML_FILE);
-
- Function<InputStream, Map<String, LinkedHashMap<String, Object>>> reader = is -> {
- YamlUtil yamlUtil = new YamlUtil();
- return yamlUtil.yamlToMap(is);
- };
-
- try {
-
- Map<String, LinkedHashMap<String, Object>> configurationMap = configurationYamlFile != null
- ? readFromFile(configurationYamlFile, reader) // load from file
- : FileUtils.readViaInputStream(CONFIGURATION_YAML_FILE, reader); // or from resource
- cassandraConfiguration = configurationMap.get(CASSANDRA_KEY);
-
- } catch (IOException e) {
- throw new RuntimeException("Failed to read configuration", e);
+ static final String CONFIGURATION_YAML_FILE = "configuration.yaml";
+ static private final Integer DEFAULT_CASSANDRA_PORT = 9042;
+ private static final String CASSANDRA = "cassandra";
+ private static final String CASSANDRA_KEY = CASSANDRA + "Config";
+ private static final String DEFAULT_KEYSPACE_NAME = "dox";
+ private static final String CASSANDRA_ADDRESSES = CASSANDRA + ".addresses";
+ private static final String CASSANDRA_DOX_KEY_STORE = CASSANDRA + ".dox.keystore";
+ private static final String CASSANDRA_AUTHENTICATE = CASSANDRA + ".authenticate";
+ private static final String CASSANDRA_USER = CASSANDRA + ".user";
+ private static final String CASSANDRA_PASSWORD = CASSANDRA + ".password";
+ private static final String CASSANDRA_SSL = CASSANDRA + ".ssl";
+ private static final String CASSANDRA_TRUSTSTORE = CASSANDRA + ".Truststore";
+ private static final String CASSANDRA_TRUSTSTORE_PASSWORD = CASSANDRA + ".TruststorePassword";
+ private static final String CASSANDRA_HOSTS_KEY = CASSANDRA + "Hosts";
+ private static final String CASSANDRA_PORT_KEY = "cassandraPort";
+ private static final String CASSANDRA_USERNAME_KEY = "username";
+ private static final String CASSANDRA_RECONNECT_TIMEOUT = "reconnectTimeout";
+ @SuppressWarnings("squid:S2068")
+ private static final String CASSANDRA_PASSWORD_KEY = "password";
+ private static final String CASSANDRA_AUTHENTICATE_KEY = "authenticate";
+ private static final String CASSANDRA_SSL_KEY = "ssl";
+ private static final String CASSANDRA_TRUSTSTORE_PATH_KEY = "truststorePath";
+ @SuppressWarnings("squid:S2068")
+ private static final String CASSANDRA_TRUSTSTORE_PASSWORD_KEY = "truststorePassword";
+ private static final String CONSISTENCY_LEVEL = CASSANDRA + ".consistencyLevel";
+ private static final String CONSISTENCY_LEVEL_KEY = "consistencyLevel";
+ private static final String LOCAL_DATA_CENTER_KEY = "localDataCenter";
+ private static final String LOCAL_DATA_CENTER = CASSANDRA + ".localDataCenter";
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationManager.class);
+ private static ConfigurationManager instance = null;
+ private final LinkedHashMap<String, Object> cassandraConfiguration;
+
+ private ConfigurationManager() {
+ String configurationYamlFile = System.getProperty(CONFIGURATION_YAML_FILE);
+ Function<InputStream, Map<String, LinkedHashMap<String, Object>>> reader = is -> {
+ YamlUtil yamlUtil = new YamlUtil();
+ return yamlUtil.yamlToMap(is);
+ };
+ try {
+ Map<String, LinkedHashMap<String, Object>> configurationMap = configurationYamlFile != null
+ ? readFromFile(configurationYamlFile, reader) // load from file
+
+ : FileUtils.readViaInputStream(CONFIGURATION_YAML_FILE, reader); // or from resource
+ cassandraConfiguration = configurationMap.get(CASSANDRA_KEY);
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to read configuration", e);
+ }
}
- }
- /**
- * Gets instance.
- *
- * @return the instance
- */
- public static ConfigurationManager getInstance() {
- if (Objects.isNull(instance)) {
- instance = new ConfigurationManager();
+ /**
+ * Gets instance.
+ *
+ * @return the instance
+ */
+ public static ConfigurationManager getInstance() {
+ if (Objects.isNull(instance)) {
+ instance = new ConfigurationManager();
+ }
+ return instance;
}
- return instance;
- }
-
- /**
- * Get addresses string [ ].
- *
- * @return the string [ ]
- */
- public String[] getAddresses() {
- String addresses = System.getProperty(CASSANDRA_ADDRESSES);
- if (Objects.nonNull(addresses)) {
- return addresses.split(",");
+ /**
+ * Get addresses string [ ].
+ *
+ * @return the string [ ]
+ */
+ public String[] getAddresses() {
+ String addresses = System.getProperty(CASSANDRA_ADDRESSES);
+ if (Objects.nonNull(addresses)) {
+ return addresses.split(",");
+ }
+ List lsAddresses = (ArrayList) cassandraConfiguration.get(CASSANDRA_HOSTS_KEY);
+ if (CollectionUtils.isEmpty(lsAddresses)) {
+ LOG.info("No Cassandra hosts are defined.");
+ }
+ String[] addressesArray;
+ addressesArray = (String[]) lsAddresses.toArray(new String[lsAddresses.size()]);
+ return addressesArray;
}
- List lsAddresses = (ArrayList) cassandraConfiguration.get(CASSANDRA_HOSTS_KEY);
- if (CollectionUtils.isEmpty(lsAddresses)) {
- LOG.info("No Cassandra hosts are defined.");
- }
-
- String[] addressesArray;
- addressesArray = (String[]) lsAddresses.toArray(new String[lsAddresses.size()]);
- return addressesArray;
- }
-
- /**
- * Gets Cassandra port.
- *
- * @return the port
- */
- public int getCassandraPort() {
- Integer cassandraPort = (Integer) cassandraConfiguration.get(CASSANDRA_PORT_KEY);
- if (Objects.isNull(cassandraPort)) {
- cassandraPort = DEFAULT_CASSANDRA_PORT;
+ /**
+ * Gets Cassandra port.
+ *
+ * @return the port
+ */
+ public int getCassandraPort() {
+ Integer cassandraPort = (Integer) cassandraConfiguration.get(CASSANDRA_PORT_KEY);
+ if (Objects.isNull(cassandraPort)) {
+ cassandraPort = DEFAULT_CASSANDRA_PORT;
+ }
+ return cassandraPort;
}
- return cassandraPort;
- }
- /**
- * Gets Cassandra reconnection timeout
- *
- * @return
- */
- public Long getReconnectTimeout() {
- Integer cassandraReconnectTimeout = (Integer) cassandraConfiguration.get(CASSANDRA_RECONNECT_TIMEOUT);
- if (Objects.isNull(cassandraReconnectTimeout)) {
- LOG.info("No Cassandra reconnect timeout are defined.");
- return null;
+ /**
+ * Gets Cassandra reconnection timeout
+ *
+ * @return
+ */
+ public Long getReconnectTimeout() {
+ Integer cassandraReconnectTimeout = (Integer) cassandraConfiguration.get(CASSANDRA_RECONNECT_TIMEOUT);
+ if (Objects.isNull(cassandraReconnectTimeout)) {
+ LOG.info("No Cassandra reconnect timeout are defined.");
+ return null;
+ }
+ return cassandraReconnectTimeout.longValue();
}
- return cassandraReconnectTimeout.longValue();
- }
- /**
- * Gets key space.
- *
- * @return the key space
- */
- public String getKeySpace() {
- String keySpace = System.getProperty(CASSANDRA_DOX_KEY_STORE);
- if (Objects.isNull(keySpace)) {
- keySpace = DEFAULT_KEYSPACE_NAME;
+ /**
+ * Gets key space.
+ *
+ * @return the key space
+ */
+ public String getKeySpace() {
+ String keySpace = System.getProperty(CASSANDRA_DOX_KEY_STORE);
+ if (Objects.isNull(keySpace)) {
+ keySpace = DEFAULT_KEYSPACE_NAME;
+ }
+ return keySpace;
}
- return keySpace;
- }
- /**
- * Gets username.
- *
- * @return the username
- */
- public String getUsername() {
- String username = System.getProperty(CASSANDRA_USER);
- if (Objects.isNull(username)) {
- username = (String) cassandraConfiguration.get(CASSANDRA_USERNAME_KEY);
+ /**
+ * Gets username.
+ *
+ * @return the username
+ */
+ public String getUsername() {
+ String username = System.getProperty(CASSANDRA_USER);
+ if (Objects.isNull(username)) {
+ username = (String) cassandraConfiguration.get(CASSANDRA_USERNAME_KEY);
+ }
+ return username;
}
- return username;
- }
- /**
- * Gets password.
- *
- * @return the password
- */
- public String getPassword() {
- String password = System.getProperty(CASSANDRA_PASSWORD);
- if (Objects.isNull(password)) {
- password = (String) cassandraConfiguration.get(CASSANDRA_PASSWORD_KEY);
+ /**
+ * Gets password.
+ *
+ * @return the password
+ */
+ public String getPassword() {
+ String password = System.getProperty(CASSANDRA_PASSWORD);
+ if (Objects.isNull(password)) {
+ password = (String) cassandraConfiguration.get(CASSANDRA_PASSWORD_KEY);
+ }
+ return password;
}
- return password;
- }
- /**
- * Gets truststore path.
- *
- * @return the truststore path
- */
- public String getTruststorePath() {
- String truststorePath = System.getProperty(CASSANDRA_TRUSTSTORE);
- if (Objects.isNull(truststorePath)) {
- truststorePath = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PATH_KEY);
+ /**
+ * Gets truststore path.
+ *
+ * @return the truststore path
+ */
+ public String getTruststorePath() {
+ String truststorePath = System.getProperty(CASSANDRA_TRUSTSTORE);
+ if (Objects.isNull(truststorePath)) {
+ truststorePath = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PATH_KEY);
+ }
+ return truststorePath;
}
- return truststorePath;
- }
- /**
- * Gets truststore password.
- *
- * @return the truststore password
- */
- public String getTruststorePassword() {
- String truststorePassword = System.getProperty(CASSANDRA_TRUSTSTORE_PASSWORD);
- if (Objects.isNull(truststorePassword)) {
- truststorePassword = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PASSWORD_KEY);
+ /**
+ * Gets truststore password.
+ *
+ * @return the truststore password
+ */
+ public String getTruststorePassword() {
+ String truststorePassword = System.getProperty(CASSANDRA_TRUSTSTORE_PASSWORD);
+ if (Objects.isNull(truststorePassword)) {
+ truststorePassword = (String) cassandraConfiguration.get(CASSANDRA_TRUSTSTORE_PASSWORD_KEY);
+ }
+ return truststorePassword;
}
- return truststorePassword;
- }
-
- /**
- * Is ssl boolean.
- *
- * @return the boolean
- */
- public boolean isSsl() {
- return getBooleanResult(CASSANDRA_SSL, CASSANDRA_SSL_KEY);
- }
- /**
- * Is authenticate boolean.
- *
- * @return the boolean
- */
- public boolean isAuthenticate() {
- return getBooleanResult(CASSANDRA_AUTHENTICATE, CASSANDRA_AUTHENTICATE_KEY);
- }
-
- private Boolean getBooleanResult(String property, String key) {
- Boolean res;
- String value;
- if (System.getProperty(property) == null) {
- value = String.valueOf(cassandraConfiguration.get(key));
- } else {
- value = System.getProperty(property);
+ /**
+ * Is ssl boolean.
+ *
+ * @return the boolean
+ */
+ public boolean isSsl() {
+ return getBooleanResult(CASSANDRA_SSL, CASSANDRA_SSL_KEY);
}
- res = Boolean.valueOf(value);
-
- return res;
- }
+ /**
+ * Is authenticate boolean.
+ *
+ * @return the boolean
+ */
+ public boolean isAuthenticate() {
+ return getBooleanResult(CASSANDRA_AUTHENTICATE, CASSANDRA_AUTHENTICATE_KEY);
+ }
- private <T> T readFromFile(String file, Function<InputStream, T> reader) throws IOException {
- try (InputStream is = new FileInputStream(file)) {
- return reader.apply(is);
+ private Boolean getBooleanResult(String property, String key) {
+ Boolean res;
+ String value;
+ if (System.getProperty(property) == null) {
+ value = String.valueOf(cassandraConfiguration.get(key));
+ } else {
+ value = System.getProperty(property);
+ }
+ res = Boolean.valueOf(value);
+ return res;
}
- }
- public String getConsistencyLevel() {
- String consistencyLevel = System.getProperty(CONSISTENCY_LEVEL);
- if (Objects.isNull(consistencyLevel)) {
- consistencyLevel = (String) cassandraConfiguration.get(CONSISTENCY_LEVEL_KEY);
+ private <T> T readFromFile(String file, Function<InputStream, T> reader) throws IOException {
+ try (InputStream is = new FileInputStream(file)) {
+ return reader.apply(is);
+ }
}
- if (Objects.isNull(consistencyLevel)) {
- consistencyLevel = "LOCAL_QUORUM";
+ public String getConsistencyLevel() {
+ String consistencyLevel = System.getProperty(CONSISTENCY_LEVEL);
+ if (Objects.isNull(consistencyLevel)) {
+ consistencyLevel = (String) cassandraConfiguration.get(CONSISTENCY_LEVEL_KEY);
+ }
+ if (Objects.isNull(consistencyLevel)) {
+ consistencyLevel = "LOCAL_QUORUM";
+ }
+ return consistencyLevel;
}
- return consistencyLevel;
- }
- public String getLocalDataCenter() {
- String localDataCenter = System.getProperty(LOCAL_DATA_CENTER);
- if (Objects.isNull(localDataCenter)) {
- localDataCenter = (String) cassandraConfiguration.get(LOCAL_DATA_CENTER_KEY);
+ public String getLocalDataCenter() {
+ String localDataCenter = System.getProperty(LOCAL_DATA_CENTER);
+ if (Objects.isNull(localDataCenter)) {
+ localDataCenter = (String) cassandraConfiguration.get(LOCAL_DATA_CENTER_KEY);
+ }
+ return localDataCenter;
}
- return localDataCenter;
- }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java
index c9e6379793..8670d58a22 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContext.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.common.session;
public interface SessionContext {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java
index 9b74cb0060..bfe94e4263 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProvider.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.common.session;
public interface SessionContextProvider {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java
index d08c6dd94a..d82ff40ab7 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/SessionContextProviderFactory.java
@@ -17,14 +17,12 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.common.session;
import org.openecomp.core.factory.api.AbstractComponentFactory;
import org.openecomp.core.factory.api.AbstractFactory;
-public abstract class SessionContextProviderFactory
- extends AbstractComponentFactory<SessionContextProvider> {
+public abstract class SessionContextProviderFactory extends AbstractComponentFactory<SessionContextProvider> {
public static SessionContextProviderFactory getInstance() {
return AbstractFactory.getInstance(SessionContextProviderFactory.class);
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java
index bbda545f80..89a7557958 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/User.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.common.session;
import lombok.AllArgsConstructor;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java
index 1d23410b89..179c9c0e3a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProvider.java
@@ -13,8 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.openecomp.sdc.common.session.impl;
import lombok.AllArgsConstructor;
@@ -39,15 +37,11 @@ public class AsdcSessionContextProvider implements SessionContextProvider {
@Override
public SessionContext get() {
if (threadUserId.get() == null) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("UserId was not set "
- + "for this thread").build());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("UserId was not set " + "for this thread").build());
}
-
if (threadTenant.get() == null) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("Tenant was not set "
- + "for this thread").build());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage("Tenant was not set " + "for this thread").build());
}
-
return new AsdcSessionContext(new User(threadUserId.get()), threadTenant.get());
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java
index 9367530bf3..02b6be4490 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/main/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImpl.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.common.session.impl;
import org.openecomp.sdc.common.session.SessionContextProvider;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
index 0bcdf8ebbf..6065426e9a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/CommonMethods.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.utilities;
import java.lang.reflect.Array;
@@ -27,7 +26,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
-
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
@@ -38,10 +36,7 @@ import org.openecomp.core.utilities.exception.NewInstanceRuntimeException;
*/
public class CommonMethods {
- private static final char[] CHARS = new char[] {
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
- };
+ private static final char[] CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
/**
* Private default constructor to prevent instantiation of the class objects.
@@ -56,11 +51,9 @@ public class CommonMethods {
*/
public static String nextUuId() {
UUID uuid = UUID.randomUUID();
-
StringBuilder buff = new StringBuilder(32);
long2string(uuid.getMostSignificantBits(), buff);
long2string(uuid.getLeastSignificantBits(), buff);
-
return buff.toString();
}
@@ -71,32 +64,27 @@ public class CommonMethods {
value <<= 4;
boolean isNegative = nextByte < 0;
nextByte = nextByte >>> 60;
-
if (isNegative) {
nextByte |= 0x08;
}
-
buff.append(CHARS[(int) nextByte]);
}
}
/**
- * Concatenates two Java arrays. The method allocates a new array and copies
- * all elements to it or returns one of input arrays if another one is
+ * Concatenates two Java arrays. The method allocates a new array and copies all elements to it or returns one of input arrays if another one is
* empty.
*
* @param <T> the type parameter
- * @param left Elements of this array will be copied to positions from 0 to <tt>left.length -
- * 1</tt> in the target array.
+ * @param left Elements of this array will be copied to positions from 0 to <tt>left.length - 1</tt> in the target array.
* @param right Elements of this array will be copied to positions from <tt>left.length</tt> to
* <tt>left.length + right.length</tt>
- * @return A newly allocate Java array that accommodates elements of source (left/right) arrays
- * or one of source arrays if another is empty, <tt>null</tt> - otherwise.
+ * @return A newly allocate Java array that accommodates elements of source (left/right) arrays or one of source arrays if another is empty,
+ * <tt>null</tt> - otherwise.
*/
@SuppressWarnings("unchecked")
public static <T> T[] concat(T[] left, T[] right) {
T[] res;
-
if (ArrayUtils.isEmpty(left)) {
res = right;
} else if (ArrayUtils.isEmpty(right)) {
@@ -106,7 +94,6 @@ public class CommonMethods {
System.arraycopy(left, 0, res, 0, left.length);
System.arraycopy(right, 0, res, left.length, right.length);
}
-
return res;
} // concat
@@ -130,25 +117,18 @@ public class CommonMethods {
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(String classname, Class<T> cls) {
-
if (StringUtils.isEmpty(classname)) {
throw new IllegalArgumentException();
}
-
if (cls == null) {
throw new IllegalArgumentException();
}
-
try {
Class<?> temp = Class.forName(classname);
-
if (!cls.isAssignableFrom(temp)) {
- throw new ClassCastException(
- String.format("Failed to cast from '%s' to '%s'", classname, cls.getName()));
+ throw new ClassCastException(String.format("Failed to cast from '%s' to '%s'", classname, cls.getName()));
}
-
Class<? extends T> impl = (Class<? extends T>) temp;
-
return newInstance(impl);
} catch (ClassNotFoundException exception) {
throw new IllegalArgumentException(exception);
@@ -166,8 +146,7 @@ public class CommonMethods {
try {
return cls.getDeclaredConstructor().newInstance();
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException ex) {
- throw new NewInstanceRuntimeException(String.format("Could not create instance for '%s'", cls.getName())
- , ex);
+ throw new NewInstanceRuntimeException(String.format("Could not create instance for '%s'", cls.getName()), ex);
}
}
@@ -236,10 +215,8 @@ public class CommonMethods {
* @param numberOfDuplications the number of duplications
* @return the string
*/
- public static String duplicateStringWithDelimiter(String arg, char separator,
- int numberOfDuplications) {
+ public static String duplicateStringWithDelimiter(String arg, char separator, int numberOfDuplications) {
StringBuilder sb = new StringBuilder();
-
for (int i = 0; i < numberOfDuplications; i++) {
if (i > 0) {
sb.append(separator);
@@ -254,12 +231,10 @@ public class CommonMethods {
*
* @param <T> the class of the objects in the set
* @param element the single element to be contained in the returned Set
- * @return an immutable set containing only the specified object. The returned set is
- * serializable.
+ * @return an immutable set containing only the specified object. The returned set is serializable.
*/
public static <T> Set<T> toSingleElementSet(T element) {
return Collections.singleton(element);
-
}
/**
@@ -271,13 +246,11 @@ public class CommonMethods {
* @param source the source
* @return the list
*/
- public static <T, S> List<Map<T, S>> mergeListsOfMap(List<Map<T, S>> target,
- List<Map<T, S>> source) {
+ public static <T, S> List<Map<T, S>> mergeListsOfMap(List<Map<T, S>> target, List<Map<T, S>> source) {
List<Map<T, S>> retList = new ArrayList<>();
if (Objects.nonNull(target)) {
retList.addAll(target);
}
-
if (Objects.nonNull(source)) {
for (Map<T, S> sourceMap : source) {
for (Map.Entry<T, S> entry : sourceMap.entrySet()) {
@@ -298,14 +271,12 @@ public class CommonMethods {
*/
public static <T> List<T> mergeLists(List<T> target, List<T> source) {
List<T> retList = new ArrayList<>();
-
if (Objects.nonNull(source)) {
retList.addAll(source);
}
if (Objects.nonNull(target)) {
retList.addAll(target);
}
-
return retList;
}
@@ -326,7 +297,6 @@ public class CommonMethods {
found = true;
}
}
-
if (!found) {
Map<T, S> newMap = new HashMap<>();
newMap.put(key, value);
@@ -334,7 +304,6 @@ public class CommonMethods {
}
}
-
/**
* Merge maps map.
*
@@ -342,8 +311,7 @@ public class CommonMethods {
* @param <S> the type parameter
* @param firstMap the firstMap
* @param secondMap the secondMap
- * @return the map
- * Second Map is overridden data from the first map
+ * @return the map Second Map is overridden data from the first map
*/
public static <T, S> Map<T, S> mergeMaps(Map<T, S> firstMap, Map<T, S> secondMap) {
Map<T, S> retMap = new HashMap<>();
@@ -355,6 +323,4 @@ public class CommonMethods {
}
return retMap;
}
-
}
-
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/deserializers/RequirementDefinitionDeserializer.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/deserializers/RequirementDefinitionDeserializer.java
index 1176a6ba8b..93bc29c958 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/deserializers/RequirementDefinitionDeserializer.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/deserializers/RequirementDefinitionDeserializer.java
@@ -19,85 +19,68 @@
*/
package org.openecomp.core.utilities.deserializers;
-import java.lang.reflect.Type;
-import java.util.Objects;
-import java.util.Optional;
-import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.lang.reflect.Type;
+import java.util.Objects;
+import java.util.Optional;
+import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
public class RequirementDefinitionDeserializer implements JsonDeserializer<RequirementDefinition> {
- static final String CAPABILITY = "capability";
- static final String NODE = "node";
- static final String RELATIONSHIP = "relationship";
- private static final String OCCURRENCES = "occurrences";
-
- @Override
- public RequirementDefinition deserialize(JsonElement jsonElement, Type type,
- JsonDeserializationContext jsonDeserializationContext) {
-
- JsonObject jsonObject = jsonElement.getAsJsonObject();
-
- RequirementDefinition requirementDefinition = new RequirementDefinition();
- setRequirementValues(jsonObject, requirementDefinition);
-
- Optional<Object[]> occurrences = handleOccurrences(jsonObject);
- occurrences.ifPresent(requirementDefinition::setOccurrences);
-
- return requirementDefinition;
- }
-
-
- private void setRequirementValues(JsonObject jsonObject,
- RequirementDefinition requirementDefinition) {
-
- JsonElement capabilityElement = jsonObject.get(CAPABILITY);
- if (!Objects.isNull(capabilityElement)) {
- requirementDefinition.setCapability(capabilityElement.getAsString());
- }
-
- JsonElement nodeElement = jsonObject.get(NODE);
- if (!Objects.isNull(nodeElement)) {
- requirementDefinition.setNode(nodeElement.getAsString());
- }
-
- JsonElement relationshipElement = jsonObject.get(RELATIONSHIP);
- if (!Objects.isNull(relationshipElement)) {
- requirementDefinition.setRelationship(relationshipElement.getAsString());
+ static final String CAPABILITY = "capability";
+ static final String NODE = "node";
+ static final String RELATIONSHIP = "relationship";
+ private static final String OCCURRENCES = "occurrences";
+
+ @Override
+ public RequirementDefinition deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) {
+ JsonObject jsonObject = jsonElement.getAsJsonObject();
+ RequirementDefinition requirementDefinition = new RequirementDefinition();
+ setRequirementValues(jsonObject, requirementDefinition);
+ Optional<Object[]> occurrences = handleOccurrences(jsonObject);
+ occurrences.ifPresent(requirementDefinition::setOccurrences);
+ return requirementDefinition;
}
- }
-
- private Optional<Object[]> handleOccurrences(JsonObject jsonObject) {
- JsonElement occurrencesElement = jsonObject.get(OCCURRENCES);
-
- if(Objects.isNull(occurrencesElement)){
- return Optional.empty();
+ private void setRequirementValues(JsonObject jsonObject, RequirementDefinition requirementDefinition) {
+ JsonElement capabilityElement = jsonObject.get(CAPABILITY);
+ if (!Objects.isNull(capabilityElement)) {
+ requirementDefinition.setCapability(capabilityElement.getAsString());
+ }
+ JsonElement nodeElement = jsonObject.get(NODE);
+ if (!Objects.isNull(nodeElement)) {
+ requirementDefinition.setNode(nodeElement.getAsString());
+ }
+ JsonElement relationshipElement = jsonObject.get(RELATIONSHIP);
+ if (!Objects.isNull(relationshipElement)) {
+ requirementDefinition.setRelationship(relationshipElement.getAsString());
+ }
}
- JsonArray occurrences = occurrencesElement.getAsJsonArray();
- Object[] fixedOccurrences = new Object[occurrences.size()];
-
- for (int i = 0; i < occurrences.size(); i++) {
- JsonElement currElement = occurrences.get(i);
-
- // values inside occurrences array can be either String or Integer
- if (currElement.isJsonPrimitive()) {
- JsonPrimitive jsonPrimitive = currElement.getAsJsonPrimitive();
-
- if (jsonPrimitive.isNumber()) {
- fixedOccurrences[i] = jsonPrimitive.getAsNumber().intValue();
- } else {
- fixedOccurrences[i] = jsonPrimitive.getAsString();
+ private Optional<Object[]> handleOccurrences(JsonObject jsonObject) {
+ JsonElement occurrencesElement = jsonObject.get(OCCURRENCES);
+ if (Objects.isNull(occurrencesElement)) {
+ return Optional.empty();
+ }
+ JsonArray occurrences = occurrencesElement.getAsJsonArray();
+ Object[] fixedOccurrences = new Object[occurrences.size()];
+ for (int i = 0; i < occurrences.size(); i++) {
+ JsonElement currElement = occurrences.get(i);
+ // values inside occurrences array can be either String or Integer
+ if (currElement.isJsonPrimitive()) {
+ JsonPrimitive jsonPrimitive = currElement.getAsJsonPrimitive();
+ if (jsonPrimitive.isNumber()) {
+ fixedOccurrences[i] = jsonPrimitive.getAsNumber().intValue();
+ } else {
+ fixedOccurrences[i] = jsonPrimitive.getAsString();
+ }
+ }
}
- }
+ return Optional.of(fixedOccurrences);
}
-
- return Optional.of(fixedOccurrences);
- }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/exception/NewInstanceRuntimeException.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/exception/NewInstanceRuntimeException.java
index 386486ff9e..97191fd2a5 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/exception/NewInstanceRuntimeException.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/exception/NewInstanceRuntimeException.java
@@ -16,7 +16,6 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.exception;
public class NewInstanceRuntimeException extends RuntimeException {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
index 2a3a3bd19e..89f1f3a293 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.file;
import java.io.ByteArrayInputStream;
@@ -54,7 +53,6 @@ public class FileContentHandler {
if (content == null || content.length == 0) {
return null;
}
-
return new ByteArrayInputStream(content);
}
@@ -101,7 +99,7 @@ public class FileContentHandler {
* Adds a file.
*
* @param filePath the file path
- * @param content the file content
+ * @param content the file content
*/
public void addFile(final String filePath, final byte[] content) {
files.put(filePath, content == null ? new byte[0] : content);
@@ -110,7 +108,7 @@ public class FileContentHandler {
/**
* Adds a file.
*
- * @param filePath the file path
+ * @param filePath the file path
* @param fileInputStream the file input stream
*/
public void addFile(final String filePath, final InputStream fileInputStream) {
@@ -123,8 +121,7 @@ public class FileContentHandler {
* @return a file path:content map
*/
public Map<String, byte[]> getFiles() {
- return files.entrySet().stream().filter(entry -> entry.getValue() != null)
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ return files.entrySet().stream().filter(entry -> entry.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
public void setFiles(final Map<String, byte[]> files) {
@@ -190,5 +187,4 @@ public class FileContentHandler {
public boolean containsFile(final String filePath) {
return files.containsKey(filePath);
}
-
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
index f69a2a060a..60ff1c172a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.utilities.file;
import java.io.ByteArrayInputStream;
@@ -43,284 +42,262 @@ import org.openecomp.sdc.common.zip.exception.ZipException;
*/
public class FileUtils {
- /**
- * Allows to consume an input stream open against a resource with a given file name.
- *
- * @param fileName the file name
- * @param function logic to be applied to the input stream
- */
- public static <T> T readViaInputStream(String fileName, Function<InputStream, T> function) {
-
- Objects.requireNonNull(fileName);
-
- // the leading slash doesn't make sense and doesn't work when used with a class loader
- URL resource = FileUtils.class.getClassLoader().getResource(fileName.startsWith("/")
- ? fileName.substring(1) : fileName);
- if (resource == null) {
- throw new IllegalArgumentException("Resource not found: " + fileName);
+ /**
+ * Allows to consume an input stream open against a resource with a given file name.
+ *
+ * @param fileName the file name
+ * @param function logic to be applied to the input stream
+ */
+ public static <T> T readViaInputStream(String fileName, Function<InputStream, T> function) {
+ Objects.requireNonNull(fileName);
+ // the leading slash doesn't make sense and doesn't work when used with a class loader
+ URL resource = FileUtils.class.getClassLoader().getResource(fileName.startsWith("/") ? fileName.substring(1) : fileName);
+ if (resource == null) {
+ throw new IllegalArgumentException("Resource not found: " + fileName);
+ }
+ return readViaInputStream(resource, function);
}
- return readViaInputStream(resource, function);
- }
-
- /**
- * Allows to consume an input stream open against a resource with a given URL.
- *
- * @param urlFile the url file
- * @param function logic to be applied to the input stream
- */
- public static <T> T readViaInputStream(URL urlFile, Function<InputStream, T> function) {
-
- Objects.requireNonNull(urlFile);
- try (InputStream is = urlFile.openStream()) {
- return function.apply(is);
- } catch (IOException exception) {
- throw new RuntimeException(exception);
+ /**
+ * Allows to consume an input stream open against a resource with a given URL.
+ *
+ * @param urlFile the url file
+ * @param function logic to be applied to the input stream
+ */
+ public static <T> T readViaInputStream(URL urlFile, Function<InputStream, T> function) {
+ Objects.requireNonNull(urlFile);
+ try (InputStream is = urlFile.openStream()) {
+ return function.apply(is);
+ } catch (IOException exception) {
+ throw new RuntimeException(exception);
+ }
}
- }
-
- /**
- * Gets file input streams.
- *
- * @param fileName the file name
- * @return the file input streams
- */
- public static List<URL> getAllLocations(String fileName) {
-
- List<URL> urls = new LinkedList<>();
- Enumeration<URL> urlFiles;
-
- try {
- urlFiles = FileUtils.class.getClassLoader().getResources(fileName);
- while (urlFiles.hasMoreElements()) {
- urls.add(urlFiles.nextElement());
- }
-
- } catch (IOException exception) {
- throw new RuntimeException(exception);
+ /**
+ * Gets file input streams.
+ *
+ * @param fileName the file name
+ * @return the file input streams
+ */
+ public static List<URL> getAllLocations(String fileName) {
+ List<URL> urls = new LinkedList<>();
+ Enumeration<URL> urlFiles;
+ try {
+ urlFiles = FileUtils.class.getClassLoader().getResources(fileName);
+ while (urlFiles.hasMoreElements()) {
+ urls.add(urlFiles.nextElement());
+ }
+ } catch (IOException exception) {
+ throw new RuntimeException(exception);
+ }
+ return urls.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(urls);
}
- return urls.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(urls);
- }
-
- /**
- * Convert to bytes byte [ ].
- *
- * @param object the object
- * @param extension the extension
- * @return the byte [ ]
- */
- public static byte[] convertToBytes(Object object, FileExtension extension) {
- if (object != null) {
- if (extension.equals(FileExtension.YAML) || extension.equals(FileExtension.YML)) {
- return new YamlUtil().objectToYaml(object).getBytes();
- } else {
- return JsonUtil.object2Json(object).getBytes();
- }
- } else {
- return new byte[]{};
+ /**
+ * Convert to bytes byte [ ].
+ *
+ * @param object the object
+ * @param extension the extension
+ * @return the byte [ ]
+ */
+ public static byte[] convertToBytes(Object object, FileExtension extension) {
+ if (object != null) {
+ if (extension.equals(FileExtension.YAML) || extension.equals(FileExtension.YML)) {
+ return new YamlUtil().objectToYaml(object).getBytes();
+ } else {
+ return JsonUtil.object2Json(object).getBytes();
+ }
+ } else {
+ return new byte[]{};
+ }
}
- }
-
- /**
- * Convert to input stream input stream.
- *
- * @param object the object
- * @param extension the extension
- * @return the input stream
- */
- public static InputStream convertToInputStream(Object object, FileExtension extension) {
- if (object != null) {
- byte[] content;
-
- if (extension.equals(FileExtension.YAML) || extension.equals(FileExtension.YML)) {
- content = new YamlUtil().objectToYaml(object).getBytes();
- } else {
- content = JsonUtil.object2Json(object).getBytes();
-
- }
- return new ByteArrayInputStream(content);
- } else {
- return null;
+ /**
+ * Convert to input stream input stream.
+ *
+ * @param object the object
+ * @param extension the extension
+ * @return the input stream
+ */
+ public static InputStream convertToInputStream(Object object, FileExtension extension) {
+ if (object != null) {
+ byte[] content;
+ if (extension.equals(FileExtension.YAML) || extension.equals(FileExtension.YML)) {
+ content = new YamlUtil().objectToYaml(object).getBytes();
+ } else {
+ content = JsonUtil.object2Json(object).getBytes();
+ }
+ return new ByteArrayInputStream(content);
+ } else {
+ return null;
+ }
}
- }
- /**
- * Load file to input stream input stream.
- *
- * @param fileName the file name
- * @return the input stream
- */
- public static InputStream loadFileToInputStream(String fileName) {
- URL urlFile = Thread.currentThread().getContextClassLoader().getResource(fileName);
- try {
- Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(fileName);
- while (en.hasMoreElements()) {
- urlFile = en.nextElement();
- }
- } catch (IOException | NullPointerException exception) {
- throw new RuntimeException(exception);
- }
- try {
- if (urlFile != null) {
- return urlFile.openStream();
- } else {
- throw new RuntimeException();
- }
- } catch (IOException | NullPointerException exception) {
- throw new RuntimeException(exception);
+ /**
+ * Load file to input stream input stream.
+ *
+ * @param fileName the file name
+ * @return the input stream
+ */
+ public static InputStream loadFileToInputStream(String fileName) {
+ URL urlFile = Thread.currentThread().getContextClassLoader().getResource(fileName);
+ try {
+ Enumeration<URL> en = Thread.currentThread().getContextClassLoader().getResources(fileName);
+ while (en.hasMoreElements()) {
+ urlFile = en.nextElement();
+ }
+ } catch (IOException | NullPointerException exception) {
+ throw new RuntimeException(exception);
+ }
+ try {
+ if (urlFile != null) {
+ return urlFile.openStream();
+ } else {
+ throw new RuntimeException();
+ }
+ } catch (IOException | NullPointerException exception) {
+ throw new RuntimeException(exception);
+ }
}
- }
-
- /**
- * To byte array byte [ ].
- *
- * @param input the input
- * @return the byte [ ]
- */
- public static byte[] toByteArray(InputStream input) {
- if (input == null) {
- return new byte[0];
- }
- try {
- return IOUtils.toByteArray(input);
- } catch (IOException exception) {
- throw new RuntimeException(
- "error while converting input stream to byte array", exception);
+ /**
+ * To byte array byte [ ].
+ *
+ * @param input the input
+ * @return the byte [ ]
+ */
+ public static byte[] toByteArray(InputStream input) {
+ if (input == null) {
+ return new byte[0];
+ }
+ try {
+ return IOUtils.toByteArray(input);
+ } catch (IOException exception) {
+ throw new RuntimeException("error while converting input stream to byte array", exception);
+ }
}
- }
- /**
- * Gets file without extention.
- *
- * @param fileName the file name
- * @return the file without extention
- */
- public static String getFileWithoutExtention(String fileName) {
- if (!fileName.contains(".")) {
- return fileName;
+ /**
+ * Gets file without extention.
+ *
+ * @param fileName the file name
+ * @return the file without extention
+ */
+ public static String getFileWithoutExtention(String fileName) {
+ if (!fileName.contains(".")) {
+ return fileName;
+ }
+ return fileName.substring(0, fileName.lastIndexOf('.'));
}
- return fileName.substring(0, fileName.lastIndexOf('.'));
- }
- public static String getFileExtension(String filename) {
- return FilenameUtils.getExtension(filename);
- }
-
- public static String getNetworkPackageName(String filename) {
- String[] split = filename.split("\\.");
- String name = null;
- if (split.length > 1) {
- name = split[0];
+ public static String getFileExtension(String filename) {
+ return FilenameUtils.getExtension(filename);
}
- return name;
- }
-
- /**
- * Gets file content map from zip.
- *
- * @param zipData the zip data
- * @return the file content map from zip
- * @throws ZipException when an error occurs while extracting zip files
- */
- public static FileContentHandler getFileContentMapFromZip(byte[] zipData)
- throws ZipException {
- final Map<String, byte[]> zipFileAndByteMap = ZipUtils.readZip(zipData, true);
- final FileContentHandler fileContentHandler = new FileContentHandler();
- zipFileAndByteMap.forEach((path, bytes) -> {
- if (bytes == null) {
- fileContentHandler.addFolder(path);
- } else {
- fileContentHandler.addFile(path, bytes);
- }
- });
- return fileContentHandler;
- }
-
- /**
- * The enum File extension.
- */
- public enum FileExtension {
+ public static String getNetworkPackageName(String filename) {
+ String[] split = filename.split("\\.");
+ String name = null;
+ if (split.length > 1) {
+ name = split[0];
+ }
+ return name;
+ }
/**
- * Json file extension.
- */
- JSON("json"),
- /**
- * Yaml file extension.
+ * Gets file content map from zip.
+ *
+ * @param zipData the zip data
+ * @return the file content map from zip
+ * @throws ZipException when an error occurs while extracting zip files
*/
- YAML("yaml"),
+ public static FileContentHandler getFileContentMapFromZip(byte[] zipData) throws ZipException {
+ final Map<String, byte[]> zipFileAndByteMap = ZipUtils.readZip(zipData, true);
+ final FileContentHandler fileContentHandler = new FileContentHandler();
+ zipFileAndByteMap.forEach((path, bytes) -> {
+ if (bytes == null) {
+ fileContentHandler.addFolder(path);
+ } else {
+ fileContentHandler.addFile(path, bytes);
+ }
+ });
+ return fileContentHandler;
+ }
+
/**
- * Yml file extension.
+ * Write files and folders map to disk in the given path
+ *
+ * @param fileContentHandler the file content handler
+ * @param dir the dir
+ * @return a map containing file names and their absolute paths
+ * @throws IOException the io exception
*/
- YML("yml");
-
- private final String displayName;
-
- FileExtension(String displayName) {
- this.displayName = displayName;
+ public static Map<String, String> writeFilesFromFileContentHandler(final FileContentHandler fileContentHandler, final Path dir)
+ throws IOException {
+ final File dirFile = dir.toFile();
+ final Map<String, String> filePaths = new HashMap<>();
+ File file;
+ for (final String folderPath : fileContentHandler.getFolderList()) {
+ file = new File(dirFile, folderPath);
+ filePaths.put(folderPath, file.getAbsolutePath());
+ if (!file.exists() && !file.mkdirs()) {
+ throw new IOException("Could not create directory " + file.getAbsolutePath());
+ }
+ }
+ for (final Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) {
+ file = new File(dirFile, fileEntry.getKey());
+ filePaths.put(fileEntry.getKey(), file.getAbsolutePath());
+ final byte[] fileBytes = fileEntry.getValue();
+ if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
+ throw new IOException("Could not create parent directory for " + file.getAbsolutePath());
+ }
+ try (final FileOutputStream fop = new FileOutputStream(file.getAbsolutePath());) {
+ fop.write(fileBytes);
+ fop.flush();
+ }
+ }
+ return filePaths;
}
/**
- * Gets display name.
+ * Verify whether the provided extension is valid Yaml/Yml extension or not.
*
- * @return the display name
+ * @param fileExtension the file extension
+ * @return the boolean
*/
- public String getDisplayName() {
- return displayName;
+ public static boolean isValidYamlExtension(String fileExtension) {
+ return fileExtension.equalsIgnoreCase(FileExtension.YML.getDisplayName()) || fileExtension
+ .equalsIgnoreCase(FileExtension.YAML.getDisplayName());
}
- }
-
- /**
- * Write files and folders map to disk in the given path
- *
- * @param fileContentHandler the file content handler
- * @param dir the dir
- * @return a map containing file names and their absolute paths
- * @throws IOException the io exception
- */
- public static Map<String, String> writeFilesFromFileContentHandler(final FileContentHandler fileContentHandler,
- final Path dir) throws IOException {
- final File dirFile = dir.toFile();
- final Map<String, String> filePaths = new HashMap<>();
- File file;
- for (final String folderPath : fileContentHandler.getFolderList()) {
- file = new File(dirFile, folderPath);
- filePaths.put(folderPath, file.getAbsolutePath());
- if (!file.exists() && !file.mkdirs()) {
- throw new IOException("Could not create directory " + file.getAbsolutePath());
- }
- }
- for (final Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) {
- file = new File(dirFile, fileEntry.getKey());
- filePaths.put(fileEntry.getKey(), file.getAbsolutePath());
- final byte[] fileBytes = fileEntry.getValue();
- if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
- throw new IOException("Could not create parent directory for " + file.getAbsolutePath());
- }
- try (final FileOutputStream fop = new FileOutputStream(file.getAbsolutePath());) {
- fop.write(fileBytes);
- fop.flush();
- }
+ /**
+ * The enum File extension.
+ */
+ public enum FileExtension {
+ /**
+ * Json file extension.
+ */
+ JSON("json"),
+ /**
+ * Yaml file extension.
+ */
+ YAML("yaml"),
+ /**
+ * Yml file extension.
+ */
+ YML("yml");
+ private final String displayName;
+
+ FileExtension(String displayName) {
+ this.displayName = displayName;
+ }
+
+ /**
+ * Gets display name.
+ *
+ * @return the display name
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
}
-
- return filePaths;
- }
-
- /**
- * Verify whether the provided extension is valid Yaml/Yml extension or not.
- *
- * @param fileExtension the file extension
- * @return the boolean
- */
- public static boolean isValidYamlExtension(String fileExtension){
- return fileExtension.equalsIgnoreCase(FileExtension.YML.getDisplayName()) ||
- fileExtension.equalsIgnoreCase(FileExtension.YAML.getDisplayName());
- }
-
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
index 2db691a781..fceef8bb51 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonSchemaDataGenerator.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,160 +17,149 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.utilities.json;
+import java.util.HashMap;
+import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import java.util.HashMap;
-import java.util.Map;
-
public class JsonSchemaDataGenerator {
- private static final String ROOT = "root";
- private static final Logger logger =
- LoggerFactory.getLogger(JsonSchemaDataGenerator.class);
- boolean includeDefaults = true;
- private JSONObject root;
- private Map<String, Object> referencesData;
-
- /**
- * Instantiates a new Json schema data generator.
- *
- * @param jsonSchema the json schema
- */
- public JsonSchemaDataGenerator(String jsonSchema) {
- if (jsonSchema == null) {
- throw new IllegalArgumentException("Input string jsonSchema can not be null");
+ private static final String ROOT = "root";
+ private static final Logger logger = LoggerFactory.getLogger(JsonSchemaDataGenerator.class);
+ boolean includeDefaults = true;
+ private JSONObject root;
+ private Map<String, Object> referencesData;
+
+ /**
+ * Instantiates a new Json schema data generator.
+ *
+ * @param jsonSchema the json schema
+ */
+ public JsonSchemaDataGenerator(String jsonSchema) {
+ if (jsonSchema == null) {
+ throw new IllegalArgumentException("Input string jsonSchema can not be null");
+ }
+ root = new JSONObject(jsonSchema);
}
- root = new JSONObject(jsonSchema);
- }
- public void setIncludeDefaults(boolean includeDefaults) {
- this.includeDefaults = includeDefaults;
- }
-
- /**
- * Generates json data that conform to the schema according to turned on flags.
- *
- * @return json that conform to the schema
- */
- public String generateData() {
- referencesData = new HashMap<>();
- JSONObject data = new JSONObject();
-
- generateData(ROOT, root,
- data);
- // "root" is dummy name to represent the top level object
- // (which, as apposed to inner objects, doesn't have a name in the schema)
- return data.has(ROOT) ? data.get(ROOT).toString() : data.toString();
- }
-
- private void generateData(String propertyName, JSONObject property, JSONObject propertyData) {
- if (property.has(JsonSchemaKeyword.TYPE)) {
- String propertyType = property.getString(JsonSchemaKeyword.TYPE);
- if (JsonSchemaKeyword.OBJECT.equals(propertyType)) {
- generateObjectData(propertyName, property, propertyData);
- } else {
- generatePrimitiveData(propertyType, propertyName, property, propertyData);
- }
- } else if (property.has(JsonSchemaKeyword.REF)) {
- generateReferenceData(propertyName, property.getString(JsonSchemaKeyword.REF), propertyData);
+ public void setIncludeDefaults(boolean includeDefaults) {
+ this.includeDefaults = includeDefaults;
}
- }
-
- private void generateObjectData(String propertyName, JSONObject property,
- JSONObject propertyData) {
- JSONObject subProperties = property.getJSONObject(JsonSchemaKeyword.PROPERTIES);
- JSONObject subPropertiesData = new JSONObject();
- for (String subPropertyName : subProperties.keySet()) {
- generateData(subPropertyName, subProperties.getJSONObject(subPropertyName),
- subPropertiesData);
+ /**
+ * Generates json data that conform to the schema according to turned on flags.
+ *
+ * @return json that conform to the schema
+ */
+ public String generateData() {
+ referencesData = new HashMap<>();
+ JSONObject data = new JSONObject();
+ generateData(ROOT, root, data);
+ // "root" is dummy name to represent the top level object
+
+ // (which, as apposed to inner objects, doesn't have a name in the schema)
+ return data.has(ROOT) ? data.get(ROOT).toString() : data.toString();
}
- if (subPropertiesData.length() > 0) {
- propertyData.put(propertyName, subPropertiesData);
+ private void generateData(String propertyName, JSONObject property, JSONObject propertyData) {
+ if (property.has(JsonSchemaKeyword.TYPE)) {
+ String propertyType = property.getString(JsonSchemaKeyword.TYPE);
+ if (JsonSchemaKeyword.OBJECT.equals(propertyType)) {
+ generateObjectData(propertyName, property, propertyData);
+ } else {
+ generatePrimitiveData(propertyType, propertyName, property, propertyData);
+ }
+ } else if (property.has(JsonSchemaKeyword.REF)) {
+ generateReferenceData(propertyName, property.getString(JsonSchemaKeyword.REF), propertyData);
+ }
}
- }
- private void generateReferenceData(String propertyName, String referencePath,
- JSONObject propertyData) {
- if (referencesData.containsKey(referencePath)) {
- Object referenceData = referencesData.get(referencePath);
- if (referenceData != null) {
- propertyData.put(propertyName, referenceData);
- }
- } else {
- generateData(propertyName, resolveReference(referencePath), propertyData);
- referencesData.put(referencePath, propertyData.opt(propertyName));
+ private void generateObjectData(String propertyName, JSONObject property, JSONObject propertyData) {
+ JSONObject subProperties = property.getJSONObject(JsonSchemaKeyword.PROPERTIES);
+ JSONObject subPropertiesData = new JSONObject();
+ for (String subPropertyName : subProperties.keySet()) {
+ generateData(subPropertyName, subProperties.getJSONObject(subPropertyName), subPropertiesData);
+ }
+ if (subPropertiesData.length() > 0) {
+ propertyData.put(propertyName, subPropertiesData);
+ }
}
- }
- private JSONObject resolveReference(String referencePath) {
- String[] keys = referencePath.replaceFirst("#/", "").split("/");
-
- JSONObject reference = root;
- for (String key : keys) {
- reference = reference.getJSONObject(key);
+ private void generateReferenceData(String propertyName, String referencePath, JSONObject propertyData) {
+ if (referencesData.containsKey(referencePath)) {
+ Object referenceData = referencesData.get(referencePath);
+ if (referenceData != null) {
+ propertyData.put(propertyName, referenceData);
+ }
+ } else {
+ generateData(propertyName, resolveReference(referencePath), propertyData);
+ referencesData.put(referencePath, propertyData.opt(propertyName));
+ }
}
- return reference;
- }
- private void generatePrimitiveData(String propertyType, String propertyName, JSONObject property,
- JSONObject propertyData) {
- if (includeDefaults) {
- populateWithDefaultValue(propertyType, propertyName, property, propertyData);
+ private JSONObject resolveReference(String referencePath) {
+ String[] keys = referencePath.replaceFirst("#/", "").split("/");
+ JSONObject reference = root;
+ for (String key : keys) {
+ reference = reference.getJSONObject(key);
+ }
+ return reference;
}
- }
- private void populateWithDefaultValue(String propertyType, String propertyName,
- JSONObject property, JSONObject propertyData) {
- if (!property.has(JsonSchemaKeyword.DEFAULT)) {
- return;
+ private void generatePrimitiveData(String propertyType, String propertyName, JSONObject property, JSONObject propertyData) {
+ if (includeDefaults) {
+ populateWithDefaultValue(propertyType, propertyName, property, propertyData);
+ }
}
- try {
- switch (propertyType) {
- case JsonSchemaKeyword.ARRAY:
- propertyData.put(propertyName, property.getJSONArray(JsonSchemaKeyword.DEFAULT));
- break;
- case JsonSchemaKeyword.BOOLEAN:
- propertyData.put(propertyName, property.getBoolean(JsonSchemaKeyword.DEFAULT));
- break;
- case JsonSchemaKeyword.INTEGER:
- propertyData.put(propertyName, property.getInt(JsonSchemaKeyword.DEFAULT));
- break;
- case JsonSchemaKeyword.NUMBER:
- propertyData.put(propertyName, property.getDouble(JsonSchemaKeyword.DEFAULT));
- break;
- case JsonSchemaKeyword.STRING:
- propertyData.put(propertyName, property.getString(JsonSchemaKeyword.DEFAULT));
- break;
- default:
- break;
- }
- } catch (JSONException exception) {
- Object defaultValue = property.get(JsonSchemaKeyword.DEFAULT);
- logger.error(String.format(
- "Invalid schema: '%s' property type is '%s' but it has a default value which is not: %s.",
- propertyName, propertyType, defaultValue), exception);
- throw exception;
+
+ private void populateWithDefaultValue(String propertyType, String propertyName, JSONObject property, JSONObject propertyData) {
+ if (!property.has(JsonSchemaKeyword.DEFAULT)) {
+ return;
+ }
+ try {
+ switch (propertyType) {
+ case JsonSchemaKeyword.ARRAY:
+ propertyData.put(propertyName, property.getJSONArray(JsonSchemaKeyword.DEFAULT));
+ break;
+ case JsonSchemaKeyword.BOOLEAN:
+ propertyData.put(propertyName, property.getBoolean(JsonSchemaKeyword.DEFAULT));
+ break;
+ case JsonSchemaKeyword.INTEGER:
+ propertyData.put(propertyName, property.getInt(JsonSchemaKeyword.DEFAULT));
+ break;
+ case JsonSchemaKeyword.NUMBER:
+ propertyData.put(propertyName, property.getDouble(JsonSchemaKeyword.DEFAULT));
+ break;
+ case JsonSchemaKeyword.STRING:
+ propertyData.put(propertyName, property.getString(JsonSchemaKeyword.DEFAULT));
+ break;
+ default:
+ break;
+ }
+ } catch (JSONException exception) {
+ Object defaultValue = property.get(JsonSchemaKeyword.DEFAULT);
+ logger.error(String
+ .format("Invalid schema: '%s' property type is '%s' but it has a default value which is not: %s.", propertyName, propertyType,
+ defaultValue), exception);
+ throw exception;
+ }
}
- }
- private static class JsonSchemaKeyword {
- private static final String DEFAULT = "default";
- private static final String TYPE = "type";
- private static final String PROPERTIES = "properties";
- private static final String ARRAY = "array";
- private static final String BOOLEAN = "boolean";
- private static final String INTEGER = "integer";
- private static final String NUMBER = "number";
- private static final String STRING = "string";
- private static final String OBJECT = "object";
- private static final String REF = "$ref";
- }
+ private static class JsonSchemaKeyword {
+
+ private static final String DEFAULT = "default";
+ private static final String TYPE = "type";
+ private static final String PROPERTIES = "properties";
+ private static final String ARRAY = "array";
+ private static final String BOOLEAN = "boolean";
+ private static final String INTEGER = "integer";
+ private static final String NUMBER = "number";
+ private static final String STRING = "string";
+ private static final String OBJECT = "object";
+ private static final String REF = "$ref";
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
index b83ad2782d..b148d6457d 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/json/JsonUtil.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.utilities.json;
import com.google.gson.Gson;
@@ -21,7 +20,6 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonIOException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -32,7 +30,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-
import org.apache.commons.collections4.CollectionUtils;
import org.everit.json.schema.EnumSchema;
import org.everit.json.schema.Schema;
@@ -46,7 +43,6 @@ import org.openecomp.core.utilities.deserializers.RequirementDefinitionDeseriali
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-
/**
* The type Json util.
*/
@@ -58,8 +54,7 @@ public class JsonUtil {
static {
gsonBuilder = new GsonBuilder();
- gsonBuilder.registerTypeAdapter(RequirementDefinition.class, new
- RequirementDefinitionDeserializer());
+ gsonBuilder.registerTypeAdapter(RequirementDefinition.class, new RequirementDefinitionDeserializer());
gson = gsonBuilder.create();
}
@@ -74,7 +69,6 @@ public class JsonUtil {
*/
public static String object2Json(Object obj) {
return sbObject2Json(obj).toString();
-
}
/**
@@ -125,13 +119,13 @@ public class JsonUtil {
return type;
}
-
/**
* Is valid json boolean.
*
* @param json the json
* @return the boolean
*/
+
//todo check https://github.com/stleary/JSON-java as replacement for this code
public static boolean isValidJson(String json) {
try {
@@ -152,30 +146,25 @@ public class JsonUtil {
public static List<String> validate(String json, String jsonSchema) {
List<ValidationException> validationErrors = validateUsingEverit(json, jsonSchema);
return validationErrors == null ? null
- : validationErrors.stream().map(JsonUtil::mapValidationExceptionToMessage)
- .collect(Collectors.toList());
+ : validationErrors.stream().map(JsonUtil::mapValidationExceptionToMessage).collect(Collectors.toList());
}
private static String mapValidationExceptionToMessage(ValidationException exception) {
Object schema = exception.getViolatedSchema();
-
if (schema instanceof EnumSchema) {
return mapEnumViolationToMessage(exception);
} else if (schema instanceof StringSchema) {
return mapStringViolationToMessage(exception);
}
-
return exception.getMessage();
}
private static String mapEnumViolationToMessage(ValidationException exception) {
Set<Object> possibleValues = ((EnumSchema) exception.getViolatedSchema()).getPossibleValues();
- return exception.getMessage().replaceFirst("enum value", possibleValues.size() == 1
- ? String.format("value. %s is the only possible value for this field",
- possibleValues.iterator().next())
- : String.format("value. Possible values: %s", CommonMethods
- .collectionToCommaSeparatedString(
- possibleValues.stream().map(Object::toString).collect(Collectors.toList()))));
+ return exception.getMessage().replaceFirst("enum value",
+ possibleValues.size() == 1 ? String.format("value. %s is the only possible value for this field", possibleValues.iterator().next())
+ : String.format("value. Possible values: %s",
+ CommonMethods.collectionToCommaSeparatedString(possibleValues.stream().map(Object::toString).collect(Collectors.toList()))));
}
private static String mapStringViolationToMessage(ValidationException validationException) {
@@ -188,25 +177,21 @@ public class JsonUtil {
}
private static List<ValidationException> validateUsingEverit(String json, String jsonSchema) {
- LOGGER.debug(
- String.format("validateUsingEverit start, json=%s, jsonSchema=%s", json, jsonSchema));
+ LOGGER.debug(String.format("validateUsingEverit start, json=%s, jsonSchema=%s", json, jsonSchema));
if (json == null || jsonSchema == null) {
throw new IllegalArgumentException("Input strings json and jsonSchema can not be null");
}
-
Schema schemaObj = SchemaLoader.load(new JSONObject(jsonSchema));
try {
schemaObj.validate(new JSONObject(json));
} catch (ValidationException ve) {
- return CollectionUtils.isEmpty(ve.getCausingExceptions()) ? Collections.singletonList(ve)
- : ve.getCausingExceptions();
+ return CollectionUtils.isEmpty(ve.getCausingExceptions()) ? Collections.singletonList(ve) : ve.getCausingExceptions();
}
return null;
}
private enum ValidationType {
PATTERN("pattern");
-
private String keyword;
ValidationType(String keyword) {
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
index 1fa96103ab..4ed85f939b 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.utilities.orchestration;
import java.util.Arrays;
import org.apache.commons.lang3.StringUtils;
+
public enum OnboardingTypesEnum {
CSAR("csar"), ZIP("zip"), MANUAL("manual"), NONE("none"), SIGNED_CSAR("signed-csar");
private final String type;
@@ -26,19 +26,16 @@ public enum OnboardingTypesEnum {
this.type = type;
}
- @Override
- public String toString() {
- return type;
- }
-
public static OnboardingTypesEnum getOnboardingTypesEnum(final String type) {
if (StringUtils.isEmpty(type)) {
return null;
}
-
- return Arrays.stream(OnboardingTypesEnum.values())
- .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equalsIgnoreCase(type))
+ return Arrays.stream(OnboardingTypesEnum.values()).filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equalsIgnoreCase(type))
.findAny().orElse(null);
}
+ @Override
+ public String toString() {
+ return type;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/convertor/ElementConvertor.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/convertor/ElementConvertor.java
index 2da562f4ea..932adbfe59 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/convertor/ElementConvertor.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/convertor/ElementConvertor.java
@@ -28,29 +28,25 @@ import org.openecomp.types.ElementPropertyName;
public abstract class ElementConvertor<T> {
- public static ElementType getElementType(Element element) {
- return ElementType
- .valueOf(element.getInfo().getProperty(ElementPropertyName.elementType.name()));
- }
+ public static ElementType getElementType(Element element) {
+ return ElementType.valueOf(element.getInfo().getProperty(ElementPropertyName.elementType.name()));
+ }
- public static String getElementName(Element element) {
- return element.getInfo().getName();
- }
+ public static String getElementName(Element element) {
+ return element.getInfo().getName();
+ }
+ abstract public T convert(Element element);
- abstract public T convert(Element element);
+ public T convert(ElementInfo elementInfo) {
+ throw new UnsupportedOperationException("convert elementInfo item is not supported ");
+ }
- public T convert( ElementInfo elementInfo) {
- throw new UnsupportedOperationException("convert elementInfo item is not supported ");
- }
+ public T convert(Item item) {
+ throw new UnsupportedOperationException("convert from item is not supported ");
+ }
-
- public T convert( Item item) {
- throw new UnsupportedOperationException("convert from item is not supported ");
- }
-
-
- public T convert( ItemVersion itemVersion) {
- throw new UnsupportedOperationException("convert from itemVersion is not supported ");
- }
+ public T convert(ItemVersion itemVersion) {
+ throw new UnsupportedOperationException("convert from itemVersion is not supported ");
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
index 32630df115..0583bed12f 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptor.java
@@ -13,99 +13,95 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.zusammen.api;
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.*;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement;
import com.amdocs.zusammen.commons.health.data.HealthInfo;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.item.*;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.Resolution;
import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
-
import java.util.Collection;
import java.util.Optional;
public interface ZusammenAdaptor {
- Collection<Item> listItems(SessionContext context);
+ Collection<Item> listItems(SessionContext context);
- Item getItem(SessionContext context, Id itemId);
+ Item getItem(SessionContext context, Id itemId);
- void deleteItem(SessionContext context, Id itemId);
+ void deleteItem(SessionContext context, Id itemId);
- Id createItem(SessionContext context, Info info);
+ Id createItem(SessionContext context, Info info);
- void updateItem(SessionContext context, Id itemId, Info info);
+ void updateItem(SessionContext context, Id itemId, Info info);
- Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId);
+ Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId);
- ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId);
+ ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId);
- Id createVersion(SessionContext context, Id itemId, Id baseVersionId,
- ItemVersionData itemVersionData);
+ Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData);
- void updateVersion(SessionContext context, Id itemId, Id versionId,
- ItemVersionData itemVersionData);
+ void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData);
- ItemVersion getVersion(SessionContext context, Id itemId, Id versionId);
+ ItemVersion getVersion(SessionContext context, Id itemId, Id versionId);
- ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId);
+ ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId);
- ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId);
+ ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId);
- void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag);
+ void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag);
- void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String version);
+ void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String version);
- void publishVersion(SessionContext context, Id itemId, Id versionId, String message);
+ void publishVersion(SessionContext context, Id itemId, Id versionId, String message);
- void syncVersion(SessionContext context, Id itemId, Id versionId);
+ void syncVersion(SessionContext context, Id itemId, Id versionId);
- void forceSyncVersion(SessionContext context, Id itemId, Id versionId);
+ void forceSyncVersion(SessionContext context, Id itemId, Id versionId);
- void cleanVersion(SessionContext context, Id itemId, Id versionId);
+ void cleanVersion(SessionContext context, Id itemId, Id versionId);
- Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext,
- Id elementId);
+ Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, Id elementId);
- Optional<Element> getElement(SessionContext context, ElementContext elementContext,
- String elementId); // TODO: 4/3/2017 change to Id
+ Optional<Element> getElement(SessionContext context, ElementContext elementContext,
+ String elementId); // TODO: 4/3/2017 change to Id
- Optional<Element> getElementByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName);
+ Optional<Element> getElementByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName);
- Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext,
- Id parentElementId);
+ Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext, Id parentElementId);
- Collection<Element> listElementData(SessionContext context, ElementContext elementContext,
- Id parentElementId);
+ Collection<Element> listElementData(SessionContext context, ElementContext elementContext, Id parentElementId);
- /**
- * Lists the sub elements of the element named elementName which is a sub element of
- * parentElementId
- */
- Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName);
+ /**
+ * Lists the sub elements of the element named elementName which is a sub element of parentElementId
+ */
+ Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName);
- Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext,
- Id parentElementId, String elementName);
+ Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName);
- Optional<ElementConflict> getElementConflict(SessionContext context,
- ElementContext elementContext, Id elementId);
+ Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext, Id elementId);
- Element saveElement(SessionContext context, ElementContext elementContext,
- ZusammenElement element, String message);
+ Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element, String message);
- void resolveElementConflict(SessionContext context, ElementContext elementContext,
- ZusammenElement element, Resolution resolution);
+ void resolveElementConflict(SessionContext context, ElementContext elementContext, ZusammenElement element, Resolution resolution);
- void revert(SessionContext context, Id itemId, Id versionId, Id revisionId);
+ void revert(SessionContext context, Id itemId, Id versionId, Id revisionId);
- ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId);
+ ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId);
- Collection<HealthInfo> checkHealth(SessionContext context);
+ Collection<HealthInfo> checkHealth(SessionContext context);
- String getVersion(SessionContext context);
+ String getVersion(SessionContext context);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptorFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptorFactory.java
index 53981ba478..1f0bbe58ec 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptorFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenAdaptorFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.zusammen.api;
import org.openecomp.core.factory.api.AbstractComponentFactory;
@@ -25,7 +24,7 @@ import org.openecomp.core.factory.api.AbstractFactory;
public abstract class ZusammenAdaptorFactory extends AbstractComponentFactory<ZusammenAdaptor> {
- public static ZusammenAdaptorFactory getInstance() {
- return AbstractFactory.getInstance(ZusammenAdaptorFactory.class);
- }
+ public static ZusammenAdaptorFactory getInstance() {
+ return AbstractFactory.getInstance(ZusammenAdaptorFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java
index f6f8b2b5d9..a6595699f5 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/core/zusammen/api/ZusammenUtil.java
@@ -31,43 +31,39 @@ import org.openecomp.types.ElementPropertyName;
public class ZusammenUtil {
- private ZusammenUtil() {
- throw new IllegalStateException("Utility class");
- }
+ private ZusammenUtil() {
+ throw new IllegalStateException("Utility class");
+ }
- public static SessionContext createSessionContext() {
- org.openecomp.sdc.common.session.SessionContext asdcSessionContext =
- SessionContextProviderFactory.getInstance().createInterface().get();
+ public static SessionContext createSessionContext() {
+ org.openecomp.sdc.common.session.SessionContext asdcSessionContext = SessionContextProviderFactory.getInstance().createInterface().get();
+ return createSessionContext(asdcSessionContext.getUser().getUserId(), asdcSessionContext.getTenant());
+ }
- return createSessionContext(asdcSessionContext.getUser().getUserId(), asdcSessionContext
- .getTenant());
- }
+ private static SessionContext createSessionContext(String user, String tenant) {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo(user));
+ sessionContext.setTenant(tenant);
+ return sessionContext;
+ }
- private static SessionContext createSessionContext(String user, String tenant) {
- SessionContext sessionContext = new SessionContext();
- sessionContext.setUser(new UserInfo(user));
- sessionContext.setTenant(tenant);
- return sessionContext;
- }
+ public static ZusammenElement buildStructuralElement(ElementType elementType, Action action) {
+ return buildStructuralElement(elementType.name(), action);
+ }
- public static ZusammenElement buildStructuralElement(ElementType elementType, Action action) {
- return buildStructuralElement(elementType.name(), action);
- }
+ public static ZusammenElement buildStructuralElement(String elementType, Action action) {
+ ZusammenElement element = buildElement(null, action);
+ Info info = new Info();
+ info.setName(elementType);
+ info.addProperty(ElementPropertyName.elementType.name(), elementType);
+ element.setInfo(info);
+ return element;
+ }
-
- public static ZusammenElement buildStructuralElement(String elementType, Action action) {
- ZusammenElement element = buildElement(null, action);
- Info info = new Info();
- info.setName(elementType);
- info.addProperty(ElementPropertyName.elementType.name(), elementType);
- element.setInfo(info);
- return element;
- }
-
- public static ZusammenElement buildElement(Id elementId, Action action) {
- ZusammenElement element = new ZusammenElement();
- element.setElementId(elementId);
- element.setAction(action);
- return element;
- }
+ public static ZusammenElement buildElement(Id elementId, Action action) {
+ ZusammenElement element = new ZusammenElement();
+ element.setElementId(elementId);
+ element.setAction(action);
+ return element;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/AsdcElement.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/AsdcElement.java
index 557226377e..6a3caa0210 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/AsdcElement.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/AsdcElement.java
@@ -25,7 +25,6 @@ import com.amdocs.zusammen.datatypes.item.Action;
import com.amdocs.zusammen.datatypes.item.Info;
import com.amdocs.zusammen.datatypes.item.Relation;
import com.amdocs.zusammen.utils.fileutils.FileUtils;
-
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -33,118 +32,115 @@ import java.util.Map;
public class AsdcElement implements Element {
- private String type;
- private String name;
- private String description;
-
- private Map<String, Object> properties;
- private byte[] data;
- private Collection<Relation> relations;
- private Collection<Element> subElements = new ArrayList<>();
- private Action action;
- private Id elementId;
-
- @Override
- public Action getAction() {
- return this.action;
- }
-
- @Override
- public Id getElementId() {
- return this.elementId;
- }
-
- @Override
- public Info getInfo() {
- Info info = new Info();
- info.setProperties(this.properties);
- info.addProperty(ElementPropertyName.elementType.name(), this.type != null ? this.type : this.name);
- info.setName(this.name);
- info.setDescription(this.description);
-
- return info;
- }
-
- @Override
- public Collection<Relation> getRelations() {
- return this.relations;
- }
-
- @Override
- public InputStream getData() {
- return FileUtils.toInputStream(this.data);
- }
-
- @Override
- public InputStream getSearchableData() {
- return null;
- }
-
- @Override
- public InputStream getVisualization() {
- return null;
- }
-
-
- @Override
- public Collection<Element> getSubElements() {
- return this.subElements;
- }
-
- public void setElementId(Id elementId) {
- this.elementId = elementId;
- }
-
- public void setData(InputStream data) {
- this.data = FileUtils.toByteArray(data);
- }
-
- public void setRelations(Collection<Relation> relations) {
- this.relations = relations;
- }
-
- public void setSubElements(Collection<Element> subElements) {
- this.subElements = subElements;
- }
-
- public void setAction(Action action) {
- this.action = action;
- }
-
- public AsdcElement addSubElement(Element element) {
- this.subElements.add(element);
- return this;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
+ private String type;
+ private String name;
+ private String description;
+ private Map<String, Object> properties;
+ private byte[] data;
+ private Collection<Relation> relations;
+ private Collection<Element> subElements = new ArrayList<>();
+ private Action action;
+ private Id elementId;
+
+ @Override
+ public Action getAction() {
+ return this.action;
+ }
+
+ public void setAction(Action action) {
+ this.action = action;
+ }
+
+ @Override
+ public Id getElementId() {
+ return this.elementId;
+ }
+
+ public void setElementId(Id elementId) {
+ this.elementId = elementId;
+ }
+
+ @Override
+ public Info getInfo() {
+ Info info = new Info();
+ info.setProperties(this.properties);
+ info.addProperty(ElementPropertyName.elementType.name(), this.type != null ? this.type : this.name);
+ info.setName(this.name);
+ info.setDescription(this.description);
+ return info;
+ }
+
+ @Override
+ public Collection<Relation> getRelations() {
+ return this.relations;
+ }
+
+ public void setRelations(Collection<Relation> relations) {
+ this.relations = relations;
+ }
+
+ @Override
+ public InputStream getData() {
+ return FileUtils.toInputStream(this.data);
+ }
+
+ public void setData(InputStream data) {
+ this.data = FileUtils.toByteArray(data);
+ }
+
+ @Override
+ public InputStream getSearchableData() {
+ return null;
+ }
+
+ @Override
+ public InputStream getVisualization() {
+ return null;
+ }
+
+ @Override
+ public Collection<Element> getSubElements() {
+ return this.subElements;
+ }
+
+ public void setSubElements(Collection<Element> subElements) {
+ this.subElements = subElements;
+ }
+
+ public AsdcElement addSubElement(Element element) {
+ this.subElements.add(element);
+ return this;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/ElementPropertyName.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/ElementPropertyName.java
index 6dad2a8316..895726c08f 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/ElementPropertyName.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-api/src/main/java/org/openecomp/types/ElementPropertyName.java
@@ -20,6 +20,5 @@
package org.openecomp.types;
public enum ElementPropertyName {
- elementType,
- compositionData
+ elementType, compositionData
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java
index 7932902dad..b65051cc52 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnector.java
@@ -13,84 +13,83 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.zusammen.db;
-import com.amdocs.zusammen.adaptor.inbound.api.types.item.*;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementConflict;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ItemVersionConflict;
import com.amdocs.zusammen.commons.health.data.HealthInfo;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.item.*;
+import com.amdocs.zusammen.datatypes.item.ElementContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.Resolution;
import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import com.amdocs.zusammen.datatypes.itemversion.Tag;
-
import java.util.Collection;
public interface ZusammenConnector {
- Collection<HealthInfo> checkHealth(SessionContext sessionContext);
-
- String getVersion(SessionContext sessionContext);
-
- Collection<Item> listItems(SessionContext context);
+ Collection<HealthInfo> checkHealth(SessionContext sessionContext);
- Item getItem(SessionContext context, Id itemId);
+ String getVersion(SessionContext sessionContext);
- Id createItem(SessionContext context, Info info);
+ Collection<Item> listItems(SessionContext context);
- void deleteItem(SessionContext context, Id itemId);
+ Item getItem(SessionContext context, Id itemId);
- void updateItem(SessionContext context, Id itemId, Info info);
+ Id createItem(SessionContext context, Info info);
+ void deleteItem(SessionContext context, Id itemId);
- Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId);
+ void updateItem(SessionContext context, Id itemId, Info info);
- ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId);
+ Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId);
- Id createVersion(SessionContext context, Id itemId, Id baseVersionId,
- ItemVersionData itemVersionData);
+ ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId);
- void updateVersion(SessionContext context, Id itemId, Id versionId,
- ItemVersionData itemVersionData);
+ Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData);
- ItemVersion getVersion(SessionContext context, Id itemId, Id versionId);
+ void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData);
- ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId);
+ ItemVersion getVersion(SessionContext context, Id itemId, Id versionId);
- void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag);
+ ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId);
- void resetVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId);
+ void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag);
- void revertVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId);
+ void resetVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId);
- ItemVersionRevisions listVersionRevisions(SessionContext context, Id itemId, Id versionId);
+ void revertVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId);
- void publishVersion(SessionContext context, Id itemId, Id versionId, String message);
+ ItemVersionRevisions listVersionRevisions(SessionContext context, Id itemId, Id versionId);
- void syncVersion(SessionContext context, Id itemId, Id versionId);
+ void publishVersion(SessionContext context, Id itemId, Id versionId, String message);
- void forceSyncVersion(SessionContext context, Id itemId, Id versionId);
+ void syncVersion(SessionContext context, Id itemId, Id versionId);
- void cleanVersion(SessionContext context, Id itemId, Id versionId);
+ void forceSyncVersion(SessionContext context, Id itemId, Id versionId);
- ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId);
+ void cleanVersion(SessionContext context, Id itemId, Id versionId);
+ ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId);
- Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext,
- Id parentElementId);
+ Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext, Id parentElementId);
- ElementInfo getElementInfo(SessionContext context, ElementContext elementContext, Id elementId);
+ ElementInfo getElementInfo(SessionContext context, ElementContext elementContext, Id elementId);
- Element getElement(SessionContext context, ElementContext elementContext, Id elementId);
+ Element getElement(SessionContext context, ElementContext elementContext, Id elementId);
- ElementConflict getElementConflict(SessionContext context, ElementContext elementContext,
- Id elementId);
+ ElementConflict getElementConflict(SessionContext context, ElementContext elementContext, Id elementId);
- Element saveElement(SessionContext context, ElementContext elementContext,
- Element element, String message);
+ Element saveElement(SessionContext context, ElementContext elementContext, Element element, String message);
- void resolveElementConflict(SessionContext context, ElementContext elementContext,
- Element element, Resolution resolution);
+ void resolveElementConflict(SessionContext context, ElementContext elementContext, Element element, Resolution resolution);
- void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef);
+ void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef);
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnectorFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnectorFactory.java
index 31a8bf598d..4f72386345 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnectorFactory.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/ZusammenConnectorFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.zusammen.db;
import org.openecomp.core.factory.api.AbstractComponentFactory;
@@ -25,7 +24,7 @@ import org.openecomp.core.factory.api.AbstractFactory;
public abstract class ZusammenConnectorFactory extends AbstractComponentFactory<ZusammenConnector> {
- public static ZusammenConnectorFactory getInstance() {
- return AbstractFactory.getInstance(ZusammenConnectorFactory.class);
- }
+ public static ZusammenConnectorFactory getInstance() {
+ return AbstractFactory.getInstance(ZusammenConnectorFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorFactoryImpl.java
index e6f9380c2b..d27475f73a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.zusammen.db.impl;
import com.amdocs.zusammen.adaptor.inbound.api.health.HealthAdaptorFactory;
@@ -28,13 +27,12 @@ import org.openecomp.core.zusammen.db.ZusammenConnector;
import org.openecomp.core.zusammen.db.ZusammenConnectorFactory;
public class ZusammenConnectorFactoryImpl extends ZusammenConnectorFactory {
- private static final ZusammenConnector INSTANCE =
- new ZusammenConnectorImpl(ItemAdaptorFactory.getInstance(),
- ItemVersionAdaptorFactory.getInstance(),
- ElementAdaptorFactory.getInstance(), HealthAdaptorFactory.getInstance());
- @Override
- public ZusammenConnector createInterface() {
- return INSTANCE;
- }
+ private static final ZusammenConnector INSTANCE = new ZusammenConnectorImpl(ItemAdaptorFactory.getInstance(),
+ ItemVersionAdaptorFactory.getInstance(), ElementAdaptorFactory.getInstance(), HealthAdaptorFactory.getInstance());
+
+ @Override
+ public ZusammenConnector createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
index 474b7303ab..f604d45287 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/db/impl/ZusammenConnectorImpl.java
@@ -45,364 +45,302 @@ import org.openecomp.sdc.common.errors.SdcRuntimeException;
public class ZusammenConnectorImpl implements ZusammenConnector {
- private static final String GET_ELEMENT_ERR_MSG =
- "Failed to get element. Item Id: %s, version Id: %s, element Id: %s message: %s";
- private static final String GET_ELEMENT_IN_REV_ERR_MSG =
- "Failed to get element. Item Id: %s, version Id: %s, revision Id: %s, element Id: %s message: %s";
- private final ItemAdaptorFactory itemAdaptorFactory;
- private final ItemVersionAdaptorFactory versionAdaptorFactory;
- private final ElementAdaptorFactory elementAdaptorFactory;
- private final HealthAdaptorFactory healthAdaptorFactory;
-
- public ZusammenConnectorImpl(
- ItemAdaptorFactory itemAdaptorFactory,
- ItemVersionAdaptorFactory versionAdaptorFactory,
- ElementAdaptorFactory elementAdaptorFactory,
- HealthAdaptorFactory healthAdaptorFactory) {
- this.itemAdaptorFactory = itemAdaptorFactory;
- this.versionAdaptorFactory = versionAdaptorFactory;
- this.elementAdaptorFactory = elementAdaptorFactory;
- this.healthAdaptorFactory = healthAdaptorFactory;
- CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
- }
-
- @Override
- public Collection<HealthInfo> checkHealth(SessionContext sessionContext) {
- return healthAdaptorFactory.createInterface(sessionContext).getHealthStatus(sessionContext);
- }
-
- @Override
- public String getVersion(SessionContext sessionContext) {
- return healthAdaptorFactory.createInterface(sessionContext).getVersion();
- }
-
- @Override
- public Collection<Item> listItems(SessionContext context) {
- Response<Collection<Item>> response = itemAdaptorFactory.createInterface(context).list(context);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- "Failed to list Items. message:" + response.getReturnCode().toString());
+ private static final String GET_ELEMENT_ERR_MSG = "Failed to get element. Item Id: %s, version Id: %s, element Id: %s message: %s";
+ private static final String GET_ELEMENT_IN_REV_ERR_MSG = "Failed to get element. Item Id: %s, version Id: %s, revision Id: %s, element Id: %s message: %s";
+ private final ItemAdaptorFactory itemAdaptorFactory;
+ private final ItemVersionAdaptorFactory versionAdaptorFactory;
+ private final ElementAdaptorFactory elementAdaptorFactory;
+ private final HealthAdaptorFactory healthAdaptorFactory;
+
+ public ZusammenConnectorImpl(ItemAdaptorFactory itemAdaptorFactory, ItemVersionAdaptorFactory versionAdaptorFactory,
+ ElementAdaptorFactory elementAdaptorFactory, HealthAdaptorFactory healthAdaptorFactory) {
+ this.itemAdaptorFactory = itemAdaptorFactory;
+ this.versionAdaptorFactory = versionAdaptorFactory;
+ this.elementAdaptorFactory = elementAdaptorFactory;
+ this.healthAdaptorFactory = healthAdaptorFactory;
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
}
- return response.getValue();
- }
-
- @Override
- public Item getItem(SessionContext context, Id itemId) {
- Response<Item> response = itemAdaptorFactory.createInterface(context).get(context, itemId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- "Failed to get Item. message:" + response.getReturnCode().toString());
+
+ @Override
+ public Collection<HealthInfo> checkHealth(SessionContext sessionContext) {
+ return healthAdaptorFactory.createInterface(sessionContext).getHealthStatus(sessionContext);
}
- return response.getValue();
- }
-
- @Override
- public Id createItem(SessionContext context, Info info) {
- Response<Id> response = itemAdaptorFactory.createInterface(context).create(context, info);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- "Failed to create Item. message:" + response.getReturnCode().toString());
+
+ @Override
+ public String getVersion(SessionContext sessionContext) {
+ return healthAdaptorFactory.createInterface(sessionContext).getVersion();
}
- return response.getValue();
- }
-
- @Override
- public void deleteItem(SessionContext context, Id itemId){
- Response<Void> response = itemAdaptorFactory.createInterface(context).delete(context, itemId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- "Failed to delete Item. message:" + response.getReturnCode().toString());
+
+ @Override
+ public Collection<Item> listItems(SessionContext context) {
+ Response<Collection<Item>> response = itemAdaptorFactory.createInterface(context).list(context);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("Failed to list Items. message:" + response.getReturnCode().toString());
+ }
+ return response.getValue();
}
- }
- @Override
- public void updateItem(SessionContext context, Id itemId, Info info) {
- Response<Void> response =
- itemAdaptorFactory.createInterface(context).update(context, itemId, info);
+ @Override
+ public Item getItem(SessionContext context, Id itemId) {
+ Response<Item> response = itemAdaptorFactory.createInterface(context).get(context, itemId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("Failed to get Item. message:" + response.getReturnCode().toString());
+ }
+ return response.getValue();
+ }
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException("failed to update Item . ItemId:" + itemId + "" +
- " message:" + response.getReturnCode().toString());
+ @Override
+ public Id createItem(SessionContext context, Info info) {
+ Response<Id> response = itemAdaptorFactory.createInterface(context).create(context, info);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("Failed to create Item. message:" + response.getReturnCode().toString());
+ }
+ return response.getValue();
}
- }
-
- @Override
- public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
- Response<Collection<ItemVersion>> versions =
- versionAdaptorFactory.createInterface(context).list(context, Space.PUBLIC, itemId);
- if (!versions.isSuccessful()) {
- throw new SdcRuntimeException("failed to list public versions. message: " +
- versions.getReturnCode().toString());
+
+ @Override
+ public void deleteItem(SessionContext context, Id itemId) {
+ Response<Void> response = itemAdaptorFactory.createInterface(context).delete(context, itemId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("Failed to delete Item. message:" + response.getReturnCode().toString());
+ }
}
- return versions.getValue();
- }
-
- @Override
- public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
- Response<ItemVersion> response = versionAdaptorFactory.createInterface(context)
- .get(context, Space.PUBLIC, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- String.format("failed to get public Item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void updateItem(SessionContext context, Id itemId, Info info) {
+ Response<Void> response = itemAdaptorFactory.createInterface(context).update(context, itemId, info);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("failed to update Item . ItemId:" + itemId + "" + " message:" + response.getReturnCode().toString());
+ }
}
- return response.getValue();
- }
-
- @Override
- public Id createVersion(SessionContext context, Id itemId, Id baseVersionId,
- ItemVersionData itemVersionData) {
- Response<Id> response = versionAdaptorFactory.createInterface(context).create(context, itemId,
- baseVersionId, itemVersionData);
- if (response.isSuccessful()) {
- return response.getValue();
- } else {
- throw new SdcRuntimeException(String.format(
- "failed to create Item Version. ItemId: %s, base versionId: %s, message: %s",
- itemId.getValue(), baseVersionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
+ Response<Collection<ItemVersion>> versions = versionAdaptorFactory.createInterface(context).list(context, Space.PUBLIC, itemId);
+ if (!versions.isSuccessful()) {
+ throw new SdcRuntimeException("failed to list public versions. message: " + versions.getReturnCode().toString());
+ }
+ return versions.getValue();
}
- }
-
- @Override
- public void updateVersion(SessionContext context, Id itemId, Id versionId,
- ItemVersionData itemVersionData) {
- Response<Void> response = versionAdaptorFactory.createInterface(context)
- .update(context, itemId, versionId, itemVersionData);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- String.format("failed to update Item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
+ Response<ItemVersion> response = versionAdaptorFactory.createInterface(context).get(context, Space.PUBLIC, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to get public Item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- }
-
- @Override
- public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
- Response<ItemVersion> response = versionAdaptorFactory.createInterface(context)
- .get(context, Space.PRIVATE, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- String.format("failed to get Item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) {
+ Response<Id> response = versionAdaptorFactory.createInterface(context).create(context, itemId, baseVersionId, itemVersionData);
+ if (response.isSuccessful()) {
+ return response.getValue();
+ } else {
+ throw new SdcRuntimeException(String
+ .format("failed to create Item Version. ItemId: %s, base versionId: %s, message: %s", itemId.getValue(), baseVersionId.getValue(),
+ response.getReturnCode().toString()));
+ }
}
- return response.getValue();
- }
-
- @Override
- public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
- Response<ItemVersionStatus> response =
- versionAdaptorFactory.createInterface(context).getStatus(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- String.format("failed to get Item Version status. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).update(context, itemId, versionId, itemVersionData);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to update Item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
}
- return response.getValue();
- }
-
- @Override
- public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
- Response<Void> response = versionAdaptorFactory.createInterface(context)
- .tag(context, itemId, versionId, null, tag);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to tag Item Version with tag %s. ItemId: %s, versionId: %s, message: %s",
- tag.getName(), itemId.getValue(), versionId.getValue(),
- response.getReturnCode().toString()));
+
+ @Override
+ public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
+ Response<ItemVersion> response = versionAdaptorFactory.createInterface(context).get(context, Space.PRIVATE, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to get Item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- }
-
- @Override
- public void resetVersionRevision(SessionContext context, Id itemId, Id versionId,
- Id revisionId) {
- Response<Void> response = versionAdaptorFactory.createInterface(context)
- .resetRevision(context, itemId, versionId, revisionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to reset Item Version back to revision: %s. ItemId: %s, versionId: %s, message:" +
- " %s",
- revisionId.getValue(), itemId.getValue(), versionId.getValue(),
- response.getReturnCode().toString()));
+
+ @Override
+ public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
+ Response<ItemVersionStatus> response = versionAdaptorFactory.createInterface(context).getStatus(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to get Item Version status. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- }
-
- @Override
- public void revertVersionRevision(SessionContext context, Id itemId, Id versionId,
- Id revisionId) {
- Response<Void> response = versionAdaptorFactory.createInterface(context)
- .revertRevision(context, itemId, versionId, revisionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to revert Item Version back to revision: %s. ItemId: %s, versionId: %s, " +
- "message: %s",
- revisionId.getValue(), itemId.getValue(), versionId.getValue(),
- response.getReturnCode().toString()));
+
+ @Override
+ public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).tag(context, itemId, versionId, null, tag);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to tag Item Version with tag %s. ItemId: %s, versionId: %s, message: %s", tag.getName(), itemId.getValue(),
+ versionId.getValue(), response.getReturnCode().toString()));
+ }
}
- }
-
- @Override
- public ItemVersionRevisions listVersionRevisions(SessionContext context, Id itemId,
- Id versionId) {
- Response<ItemVersionRevisions> response =
- versionAdaptorFactory.createInterface(context)
- .listRevisions(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to list revisions of Item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void resetVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).resetRevision(context, itemId, versionId, revisionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to reset Item Version back to revision: %s. ItemId: %s, versionId: %s, message:" + " %s", revisionId.getValue(),
+ itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+ }
}
- return response.getValue();
- }
-
-
- @Override
- public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
- Response<Void> response =
- versionAdaptorFactory.createInterface(context).publish(context, itemId, versionId, message);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to publish item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void revertVersionRevision(SessionContext context, Id itemId, Id versionId, Id revisionId) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).revertRevision(context, itemId, versionId, revisionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to revert Item Version back to revision: %s. ItemId: %s, versionId: %s, " + "message: %s", revisionId.getValue(),
+ itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+ }
}
- }
-
- @Override
- public void syncVersion(SessionContext context, Id itemId, Id versionId) {
- Response<MergeResult> response =
- versionAdaptorFactory.createInterface(context).sync(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to sync item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public ItemVersionRevisions listVersionRevisions(SessionContext context, Id itemId, Id versionId) {
+ Response<ItemVersionRevisions> response = versionAdaptorFactory.createInterface(context).listRevisions(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to list revisions of Item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- }
-
- @Override
- public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
- Response<MergeResult> response =
- versionAdaptorFactory.createInterface(context).forceSync(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to force sync item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).publish(context, itemId, versionId, message);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to publish item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
}
- }
-
- @Override
- public void cleanVersion(SessionContext context, Id itemId, Id versionId) {
- Response<Void> response =
- versionAdaptorFactory.createInterface(context).delete(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "failed to clean item Version. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void syncVersion(SessionContext context, Id itemId, Id versionId) {
+ Response<MergeResult> response = versionAdaptorFactory.createInterface(context).sync(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to sync item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
}
- }
-
- @Override
- public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
- Response<ItemVersionConflict> response =
- versionAdaptorFactory.createInterface(context).getConflict(context, itemId, versionId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String
- .format("failed to get Item Version conflict. ItemId: %s, versionId: %s, message: %s",
- itemId.getValue(), versionId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
+ Response<MergeResult> response = versionAdaptorFactory.createInterface(context).forceSync(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to force sync item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
}
- return response.getValue();
- }
-
- @Override
- public Collection<ElementInfo> listElements(SessionContext context,
- ElementContext elementContext,
- Id parentElementId) {
- Response<Collection<ElementInfo>> response = elementAdaptorFactory
- .createInterface(context).list(context, elementContext, parentElementId);
- if (response.isSuccessful()) {
- return response.getValue();
- } else {
- throw new SdcRuntimeException(response.getReturnCode().toString());
+
+ @Override
+ public void cleanVersion(SessionContext context, Id itemId, Id versionId) {
+ Response<Void> response = versionAdaptorFactory.createInterface(context).delete(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to clean item Version. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ }
+
+ @Override
+ public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
+ Response<ItemVersionConflict> response = versionAdaptorFactory.createInterface(context).getConflict(context, itemId, versionId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("failed to get Item Version conflict. ItemId: %s, versionId: %s, message: %s", itemId.getValue(), versionId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- }
+ @Override
+ public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext, Id parentElementId) {
+ Response<Collection<ElementInfo>> response = elementAdaptorFactory.createInterface(context).list(context, elementContext, parentElementId);
+ if (response.isSuccessful()) {
+ return response.getValue();
+ } else {
+ throw new SdcRuntimeException(response.getReturnCode().toString());
+ }
+ }
- @Override
- public ElementInfo getElementInfo(SessionContext context, ElementContext elementContext,
- Id elementId) {
- Response<ElementInfo> response =
- elementAdaptorFactory.createInterface(context).getInfo(context, elementContext, elementId);
- if (!response.isSuccessful()) {
- throw buildGetElementException(elementContext, elementId,
- response.getReturnCode().toString());
+ @Override
+ public ElementInfo getElementInfo(SessionContext context, ElementContext elementContext, Id elementId) {
+ Response<ElementInfo> response = elementAdaptorFactory.createInterface(context).getInfo(context, elementContext, elementId);
+ if (!response.isSuccessful()) {
+ throw buildGetElementException(elementContext, elementId, response.getReturnCode().toString());
+ }
+ return response.getValue();
+ }
+ @Override
+ public Element getElement(SessionContext context, ElementContext elementContext, Id elementId) {
+ Response<Element> response = elementAdaptorFactory.createInterface(context).get(context, elementContext, elementId);
+ if (!response.isSuccessful()) {
+ throw buildGetElementException(elementContext, elementId, response.getReturnCode().toString());
+ }
+ return response.getValue();
}
- return response.getValue();
- }
-
- @Override
- public Element getElement(SessionContext context, ElementContext elementContext,
- Id elementId) {
- Response<Element> response =
- elementAdaptorFactory.createInterface(context).get(context, elementContext, elementId);
- if (!response.isSuccessful()) {
- throw buildGetElementException(elementContext, elementId,
- response.getReturnCode().toString());
+
+ @Override
+ public ElementConflict getElementConflict(SessionContext context, ElementContext elementContext, Id elementId) {
+ Response<ElementConflict> response = elementAdaptorFactory.createInterface(context).getConflict(context, elementContext, elementId);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String.format("Failed to get element conflict. Item Id: %s, version Id: %s, element Id: %s message: %s",
+ elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(), elementId.getValue(),
+ response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- return response.getValue();
- }
-
- @Override
- public ElementConflict getElementConflict(SessionContext context, ElementContext elementContext,
- Id elementId) {
- Response<ElementConflict> response = elementAdaptorFactory.createInterface(context)
- .getConflict(context, elementContext, elementId);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String.format(
- "Failed to get element conflict. Item Id: %s, version Id: %s, element Id: %s message: %s",
- elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(),
- elementId.getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public Element saveElement(SessionContext context, ElementContext elementContext, Element element, String message) {
+ Response<Element> response = elementAdaptorFactory.createInterface(context).save(context, elementContext, element, message);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException(String
+ .format("Failed to create element %s. ItemId: %s, versionId: %s, message: %s", element.getElementId().getValue(),
+ elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(), response.getReturnCode().toString()));
+ }
+ return response.getValue();
}
- return response.getValue();
- }
-
- @Override
- public Element saveElement(SessionContext context, ElementContext elementContext, Element element, String message) {
- Response<Element> response = elementAdaptorFactory.createInterface(context)
- .save(context, elementContext, element, message);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(String
- .format("Failed to create element %s. ItemId: %s, versionId: %s, message: %s",
- element.getElementId().getValue(), elementContext.getItemId().getValue(),
- elementContext.getVersionId().getValue(), response.getReturnCode().toString()));
+
+ @Override
+ public void resolveElementConflict(SessionContext context, ElementContext elementContext, Element element, Resolution resolution) {
+ Response<Void> response = elementAdaptorFactory.createInterface(context).resolveConflict(context, elementContext, element, resolution);
+ if (!response.isSuccessful()) {
+ throw new SdcRuntimeException("Failed to resolve conflict. message:" + response.getReturnCode().toString());
+ }
}
- return response.getValue();
- }
-
- @Override
- public void resolveElementConflict(SessionContext context, ElementContext elementContext, Element element,
- Resolution resolution) {
- Response<Void> response = elementAdaptorFactory.createInterface(context)
- .resolveConflict(context, elementContext, element, resolution);
- if (!response.isSuccessful()) {
- throw new SdcRuntimeException(
- "Failed to resolve conflict. message:" + response.getReturnCode().toString());
+
+ @Override
+ public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String revisionId) {
+ // no-op, required by the interface
}
- }
-
- @Override
- public void resetVersionHistory(SessionContext context, Id itemId, Id versionId,
- String revisionId) {
- // no-op, required by the interface
- }
-
- private SdcRuntimeException buildGetElementException(ElementContext elementContext, Id elementId,
- String zusammenErrorMessage) {
- if (elementContext.getRevisionId() == null) {
- return new SdcRuntimeException(String.format(GET_ELEMENT_ERR_MSG,
- elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(),
- elementId.getValue(), zusammenErrorMessage));
+
+ private SdcRuntimeException buildGetElementException(ElementContext elementContext, Id elementId, String zusammenErrorMessage) {
+ if (elementContext.getRevisionId() == null) {
+ return new SdcRuntimeException(String
+ .format(GET_ELEMENT_ERR_MSG, elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(), elementId.getValue(),
+ zusammenErrorMessage));
+ }
+ return new SdcRuntimeException(String
+ .format(GET_ELEMENT_IN_REV_ERR_MSG, elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(),
+ elementContext.getRevisionId().getValue(), elementId.getValue(), zusammenErrorMessage));
}
- return new SdcRuntimeException(String.format(GET_ELEMENT_IN_REV_ERR_MSG,
- elementContext.getItemId().getValue(), elementContext.getVersionId().getValue(),
- elementContext.getRevisionId().getValue(),
- elementId.getValue(), zusammenErrorMessage));
- }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
index 05c7a1a72a..3d4af282b5 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/CassandraConnectionInitializer.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.core.zusammen.impl;
import java.util.function.Supplier;
@@ -24,16 +23,14 @@ public class CassandraConnectionInitializer {
private static final String CASSANDRA_PREFIX = "cassandra.";
private static final String DATA_CENTER_PROPERTY_NAME = CASSANDRA_PREFIX + "datacenter";
- private static final String CONSISTENCY_LEVEL_PROPERTY_NAME =
- CASSANDRA_PREFIX + "consistency.level";
+ private static final String CONSISTENCY_LEVEL_PROPERTY_NAME = CASSANDRA_PREFIX + "consistency.level";
private static final String CASSANDRA_RECONNECT_TIMEOUT = CASSANDRA_PREFIX + "reconnection.delay";
private static final String NODES_PROPERTY_NAME = CASSANDRA_PREFIX + "nodes";
private static final String CASSANDRA_PORT_PROPERTY_NAME = CASSANDRA_PREFIX + "port";
private static final String AUTHENTICATE_PROPERTY_NAME = CASSANDRA_PREFIX + "authenticate";
private static final String SSL_PROPERTY_NAME = CASSANDRA_PREFIX + "ssl";
private static final String TRUSTSTORE_PROPERTY_NAME = CASSANDRA_PREFIX + "truststore";
- private static final String TRUSTSTORE_PASSWORD_PROPERTY_NAME =
- CASSANDRA_PREFIX + "truststore.password";
+ private static final String TRUSTSTORE_PASSWORD_PROPERTY_NAME = CASSANDRA_PREFIX + "truststore.password";
private static final String USER_PROPERTY_NAME = CASSANDRA_PREFIX + "user";
private static final String PASSWORD_PROPERTY_NAME = CASSANDRA_PREFIX + "password";
private static final String KEYSPACE_PROPERTY_NAME = CASSANDRA_PREFIX + "keyspace";
@@ -50,8 +47,7 @@ public class CassandraConnectionInitializer {
private static class DeferredInitializer {
static {
- setSystemProperty(NODES_PROPERTY_NAME, () ->
- StringUtils.join(CassandraUtils.getAddresses(), ','));
+ setSystemProperty(NODES_PROPERTY_NAME, () -> StringUtils.join(CassandraUtils.getAddresses(), ','));
setSystemProperty(CASSANDRA_PORT_PROPERTY_NAME, () -> Integer.toString(CassandraUtils.getCassandraPort()));
setBooleanSystemProperty(AUTHENTICATE_PROPERTY_NAME, CassandraUtils::isAuthenticate);
setBooleanSystemProperty(SSL_PROPERTY_NAME, CassandraUtils::isSsl);
@@ -61,12 +57,12 @@ public class CassandraConnectionInitializer {
setSystemProperty(PASSWORD_PROPERTY_NAME, CassandraUtils::getPassword);
setSystemProperty(KEYSPACE_PROPERTY_NAME, () -> ZUSAMMEN);
setNullableSystemProperty(DATA_CENTER_PROPERTY_NAME, CassandraUtils::getLocalDataCenter);
- setNullableSystemProperty(CONSISTENCY_LEVEL_PROPERTY_NAME,
- CassandraUtils::getConsistencyLevel);
+ setNullableSystemProperty(CONSISTENCY_LEVEL_PROPERTY_NAME, CassandraUtils::getConsistencyLevel);
setSystemProperty(CASSANDRA_RECONNECT_TIMEOUT, () -> Long.toString(CassandraUtils.getReconnectTimeout()));
}
- private DeferredInitializer() { }
+ private DeferredInitializer() {
+ }
@SuppressWarnings("EmptyMethod")
static void init() {
@@ -74,7 +70,6 @@ public class CassandraConnectionInitializer {
}
private static void setSystemProperty(String name, Supplier<String> valueSupplier) {
-
if (System.getProperty(name) == null) {
System.setProperty(name, valueSupplier.get());
}
@@ -85,7 +80,6 @@ public class CassandraConnectionInitializer {
}
private static void setNullableSystemProperty(String name, Supplier<String> valueSupplier) {
-
if ((System.getProperty(name) == null) && (valueSupplier.get() != null)) {
System.setProperty(name, valueSupplier.get());
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ItemElementLoggerTargetServiceName.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ItemElementLoggerTargetServiceName.java
index 9ac46fda8b..b93e110768 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ItemElementLoggerTargetServiceName.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ItemElementLoggerTargetServiceName.java
@@ -21,15 +21,16 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ItemElementLoggerTargetServiceName {
- ITEM_CREATION("Item Creation"),
- ITEM_VERSION_CREATION("Item Version Creation"),
- ELEMENT_CREATION("Element Creation"),
- ELEMENT_UPDATE("Element Update"),
- ELEMENT_LIST("Element List"),
- ELEMENT_GET("Element Get"),
- ELEMENT_GET_BY_PROPERTY("Element Get By Property"),
- ITEM_RETRIEVAL("Item retrieval"),
- ITEM_VERSION_RETRIEVAL("Item version retrieval)");
-
- private final String description;
+ // @formatter:off
+ ITEM_CREATION("Item Creation"),
+ ITEM_VERSION_CREATION("Item Version Creation"),
+ ELEMENT_CREATION("Element Creation"),
+ ELEMENT_UPDATE("Element Update"),
+ ELEMENT_LIST("Element List"),
+ ELEMENT_GET("Element Get"),
+ ELEMENT_GET_BY_PROPERTY("Element Get By Property"),
+ ITEM_RETRIEVAL("Item retrieval"),
+ ITEM_VERSION_RETRIEVAL("Item version retrieval)");
+ // @formatter:on
+ private final String description;
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorFactoryImpl.java
index edc1abf108..982f7869fc 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.core.zusammen.impl;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
@@ -25,11 +24,11 @@ import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
import org.openecomp.core.zusammen.db.ZusammenConnectorFactory;
public class ZusammenAdaptorFactoryImpl extends ZusammenAdaptorFactory {
- private static final ZusammenAdaptor INSTANCE =
- new ZusammenAdaptorImpl(ZusammenConnectorFactory.getInstance().createInterface());
- @Override
- public ZusammenAdaptor createInterface() {
- return INSTANCE;
- }
+ private static final ZusammenAdaptor INSTANCE = new ZusammenAdaptorImpl(ZusammenConnectorFactory.getInstance().createInterface());
+
+ @Override
+ public ZusammenAdaptor createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
index 4efa2486a2..a5d61f4189 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-zusammen-lib/openecomp-zusammen-core/src/main/java/org/openecomp/core/zusammen/impl/ZusammenAdaptorImpl.java
@@ -43,249 +43,211 @@ import org.openecomp.core.zusammen.db.ZusammenConnector;
public class ZusammenAdaptorImpl implements ZusammenAdaptor {
- private ZusammenConnector connector;
-
- public ZusammenAdaptorImpl(ZusammenConnector connector) {
- this.connector = connector;
- }
-
- @Override
- public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext,
- Id elementId) {
- return Optional.ofNullable(connector.getElementInfo(context, elementContext, elementId));
- }
-
- @Override
- public Optional<Element> getElement(SessionContext context, ElementContext elementContext,
- String elementId) {
- return Optional.ofNullable(connector.getElement(context, elementContext, new Id(elementId)));
- }
-
- @Override
- public Optional<Element> getElementByName(
- SessionContext context, ElementContext elementContext, Id parentElementId,
- String elementName) {
- Collection<ElementInfo> elementInfos =
- connector.listElements(context, elementContext, parentElementId);
- Predicate<ElementInfo> elementInfoPredicate = elementInfo -> elementInfo.getInfo() != null
- && elementName.equals(elementInfo.getInfo().getName());
- return getFirstElementInfo(elementInfos, elementInfoPredicate)
- .flatMap(elementInfo -> getElement(context, elementContext,
- elementInfo.getId().getValue()));
- }
-
- @Override
- public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext,
- Id parentElementId) {
- return connector.listElements(context, elementContext, parentElementId);
- }
-
- @Override
- public Collection<Element> listElementData(SessionContext context,
- ElementContext elementContext,
- Id parentElementId) {
- Collection<ElementInfo> elementInfoList = connector.listElements(context, elementContext,
- parentElementId);
-
- return elementInfoList == null
- ? new ArrayList<>()
- : elementInfoList.stream()
- .map(elementInfo -> connector.getElement(context, elementContext, elementInfo.getId()))
- .collect(Collectors.toList());
- }
-
-
- @Override
- public Collection<ElementInfo> listElementsByName(
- SessionContext context, ElementContext elementContext, Id parentElementId,
- String elementName) {
- Optional<ElementInfo> elementInfoByName =
- getElementInfoByName(context, elementContext, parentElementId, elementName);
-
- return elementInfoByName.isPresent()
- ? connector.listElements(context, elementContext, elementInfoByName.get().getId())
- : new ArrayList<>();
- }
-
- @Override
- public Optional<ElementInfo> getElementInfoByName(
- SessionContext context, ElementContext elementContext, Id parentElementId,
- String elementName) {
- Collection<ElementInfo> elementInfos =
- connector.listElements(context, elementContext, parentElementId);
- return getFirstElementInfo(elementInfos,
- elementInfo -> elementInfo.getInfo() != null
- && elementName.equals(elementInfo.getInfo().getName()));
- }
-
- @Override
- public Optional<ElementConflict> getElementConflict(SessionContext context,
- ElementContext elementContext,
- Id elementId) {
- return Optional.ofNullable(connector.getElementConflict(context, elementContext, elementId));
- }
-
- @Override
- public Element saveElement(SessionContext context, ElementContext elementContext,
- ZusammenElement element, String message) {
- enrichElementHierarchyRec(context, elementContext, null, element);
- return connector.saveElement(context, elementContext, element, message);
- }
-
- @Override
- public void resolveElementConflict(SessionContext context, ElementContext elementContext,
- ZusammenElement element, Resolution resolution) {
- connector.resolveElementConflict(context, elementContext, element, resolution);
- }
-
- private void enrichElementHierarchyRec(SessionContext context, ElementContext
- elementContext, Id parentElementId, ZusammenElement element) {
- if (element.getAction() == Action.CREATE) {
- return;
- }
- locateElementAndUpdateAction(context, elementContext, parentElementId, element);
- element.getSubElements().forEach(subElement -> enrichElementHierarchyRec(
- context, elementContext, element.getElementId(), (ZusammenElement) subElement));
- }
-
- // should be applied only for structural elements
- private void locateElementAndUpdateAction(SessionContext context, ElementContext elementContext,
- Id parentElementId, ZusammenElement element) {
- if (element.getElementId() != null) {
- return;
- }
- if (element.getInfo() == null || element.getInfo().getName() == null) {
- throw new IllegalArgumentException("When saving element to zusammen - its Id or name must be supplied");
- }
- Optional<ElementInfo> elementInfo =
- getElementInfoByName(context, elementContext, parentElementId, element.getInfo().getName());
- if (elementInfo.isPresent()) {
- element.setElementId(elementInfo.get().getId());
- if (element.getAction() == null) {
- element.setAction(Action.IGNORE);
- }
- } else {
- element.setAction(Action.CREATE);
- }
- }
-
- private Optional<ElementInfo> getFirstElementInfo(Collection<ElementInfo> elementInfos,
- Predicate<ElementInfo> elementInfoPredicate) {
- return elementInfos.stream()
- .filter(elementInfoPredicate)
- .findFirst();
- }
-
- @Override
- public Collection<Item> listItems(SessionContext context) {
- return connector.listItems(context);
- }
-
- @Override
- public Item getItem(SessionContext context, Id itemId) {
- return connector.getItem(context, itemId);
- }
-
- @Override
- public Id createItem(SessionContext context, Info info) {
- return connector.createItem(context, info);
- }
-
- @Override
- public void deleteItem(SessionContext context, Id itemId){
- connector.deleteItem(context,itemId);
- }
-
- @Override
- public void updateItem(SessionContext context, Id itemId, Info info) {
- connector.updateItem(context, itemId, info);
- }
-
- @Override
- public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
- return connector.listPublicVersions(context, itemId);
- }
-
- @Override
- public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
- return connector.getPublicVersion(context, itemId, versionId);
- }
-
- @Override
- public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
- return connector.getVersion(context, itemId, versionId);
- }
-
- @Override
- public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
- return connector.getVersionStatus(context, itemId, versionId);
- }
-
- @Override
- public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
- return connector.getVersionConflict(context, itemId, versionId);
- }
-
- @Override
- public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData
- itemVersionData) {
- return connector.createVersion(context, itemId, baseVersionId, itemVersionData);
- }
-
- @Override
- public void updateVersion(SessionContext context, Id itemId, Id versionId,
- ItemVersionData itemVersionData) {
- connector.updateVersion(context, itemId, versionId, itemVersionData);
- }
-
- @Override
- public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
- connector.tagVersion(context, itemId, versionId, tag);
- }
-
- @Override
- public void resetVersionHistory(SessionContext context, Id itemId, Id versionId,
- String changeRef) {
- connector.resetVersionHistory(context, itemId, versionId, changeRef);
- }
-
- @Override
- public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
- connector.publishVersion(context, itemId, versionId, message);
- }
-
- @Override
- public void syncVersion(SessionContext context, Id itemId, Id versionId) {
- connector.syncVersion(context, itemId, versionId);
- }
-
- @Override
- public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
- connector.forceSyncVersion(context, itemId, versionId);
- }
-
- @Override
- public void cleanVersion(SessionContext context, Id itemId, Id versionId) {
- connector.cleanVersion(context, itemId, versionId);
- }
-
- @Override
- public void revert(SessionContext context, Id itemId, Id versionId, Id revisionId) {
- connector.revertVersionRevision(context, itemId, versionId, revisionId);
- }
-
- @Override
- public ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId) {
- return connector.listVersionRevisions(context, itemId, versionId);
- }
-
- @Override
- public Collection<HealthInfo> checkHealth(SessionContext context) {
- return connector.checkHealth(context);
- }
-
- @Override
- public String getVersion(SessionContext context) {
- return connector.getVersion(context);
- }
+ private ZusammenConnector connector;
+
+ public ZusammenAdaptorImpl(ZusammenConnector connector) {
+ this.connector = connector;
+ }
+
+ @Override
+ public Optional<ElementInfo> getElementInfo(SessionContext context, ElementContext elementContext, Id elementId) {
+ return Optional.ofNullable(connector.getElementInfo(context, elementContext, elementId));
+ }
+
+ @Override
+ public Optional<Element> getElement(SessionContext context, ElementContext elementContext, String elementId) {
+ return Optional.ofNullable(connector.getElement(context, elementContext, new Id(elementId)));
+ }
+
+ @Override
+ public Optional<Element> getElementByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName) {
+ Collection<ElementInfo> elementInfos = connector.listElements(context, elementContext, parentElementId);
+ Predicate<ElementInfo> elementInfoPredicate = elementInfo -> elementInfo.getInfo() != null && elementName
+ .equals(elementInfo.getInfo().getName());
+ return getFirstElementInfo(elementInfos, elementInfoPredicate)
+ .flatMap(elementInfo -> getElement(context, elementContext, elementInfo.getId().getValue()));
+ }
+
+ @Override
+ public Collection<ElementInfo> listElements(SessionContext context, ElementContext elementContext, Id parentElementId) {
+ return connector.listElements(context, elementContext, parentElementId);
+ }
+
+ @Override
+ public Collection<Element> listElementData(SessionContext context, ElementContext elementContext, Id parentElementId) {
+ Collection<ElementInfo> elementInfoList = connector.listElements(context, elementContext, parentElementId);
+ return elementInfoList == null ? new ArrayList<>()
+ : elementInfoList.stream().map(elementInfo -> connector.getElement(context, elementContext, elementInfo.getId()))
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Collection<ElementInfo> listElementsByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName) {
+ Optional<ElementInfo> elementInfoByName = getElementInfoByName(context, elementContext, parentElementId, elementName);
+ return elementInfoByName.isPresent() ? connector.listElements(context, elementContext, elementInfoByName.get().getId()) : new ArrayList<>();
+ }
+
+ @Override
+ public Optional<ElementInfo> getElementInfoByName(SessionContext context, ElementContext elementContext, Id parentElementId, String elementName) {
+ Collection<ElementInfo> elementInfos = connector.listElements(context, elementContext, parentElementId);
+ return getFirstElementInfo(elementInfos, elementInfo -> elementInfo.getInfo() != null && elementName.equals(elementInfo.getInfo().getName()));
+ }
+
+ @Override
+ public Optional<ElementConflict> getElementConflict(SessionContext context, ElementContext elementContext, Id elementId) {
+ return Optional.ofNullable(connector.getElementConflict(context, elementContext, elementId));
+ }
+
+ @Override
+ public Element saveElement(SessionContext context, ElementContext elementContext, ZusammenElement element, String message) {
+ enrichElementHierarchyRec(context, elementContext, null, element);
+ return connector.saveElement(context, elementContext, element, message);
+ }
+
+ @Override
+ public void resolveElementConflict(SessionContext context, ElementContext elementContext, ZusammenElement element, Resolution resolution) {
+ connector.resolveElementConflict(context, elementContext, element, resolution);
+ }
+
+ private void enrichElementHierarchyRec(SessionContext context, ElementContext elementContext, Id parentElementId, ZusammenElement element) {
+ if (element.getAction() == Action.CREATE) {
+ return;
+ }
+ locateElementAndUpdateAction(context, elementContext, parentElementId, element);
+ element.getSubElements()
+ .forEach(subElement -> enrichElementHierarchyRec(context, elementContext, element.getElementId(), (ZusammenElement) subElement));
+ }
+
+ // should be applied only for structural elements
+ private void locateElementAndUpdateAction(SessionContext context, ElementContext elementContext, Id parentElementId, ZusammenElement element) {
+ if (element.getElementId() != null) {
+ return;
+ }
+ if (element.getInfo() == null || element.getInfo().getName() == null) {
+ throw new IllegalArgumentException("When saving element to zusammen - its Id or name must be supplied");
+ }
+ Optional<ElementInfo> elementInfo = getElementInfoByName(context, elementContext, parentElementId, element.getInfo().getName());
+ if (elementInfo.isPresent()) {
+ element.setElementId(elementInfo.get().getId());
+ if (element.getAction() == null) {
+ element.setAction(Action.IGNORE);
+ }
+ } else {
+ element.setAction(Action.CREATE);
+ }
+ }
+
+ private Optional<ElementInfo> getFirstElementInfo(Collection<ElementInfo> elementInfos, Predicate<ElementInfo> elementInfoPredicate) {
+ return elementInfos.stream().filter(elementInfoPredicate).findFirst();
+ }
+
+ @Override
+ public Collection<Item> listItems(SessionContext context) {
+ return connector.listItems(context);
+ }
+
+ @Override
+ public Item getItem(SessionContext context, Id itemId) {
+ return connector.getItem(context, itemId);
+ }
+
+ @Override
+ public Id createItem(SessionContext context, Info info) {
+ return connector.createItem(context, info);
+ }
+
+ @Override
+ public void deleteItem(SessionContext context, Id itemId) {
+ connector.deleteItem(context, itemId);
+ }
+
+ @Override
+ public void updateItem(SessionContext context, Id itemId, Info info) {
+ connector.updateItem(context, itemId, info);
+ }
+
+ @Override
+ public Collection<ItemVersion> listPublicVersions(SessionContext context, Id itemId) {
+ return connector.listPublicVersions(context, itemId);
+ }
+
+ @Override
+ public ItemVersion getPublicVersion(SessionContext context, Id itemId, Id versionId) {
+ return connector.getPublicVersion(context, itemId, versionId);
+ }
+
+ @Override
+ public ItemVersion getVersion(SessionContext context, Id itemId, Id versionId) {
+ return connector.getVersion(context, itemId, versionId);
+ }
+
+ @Override
+ public ItemVersionStatus getVersionStatus(SessionContext context, Id itemId, Id versionId) {
+ return connector.getVersionStatus(context, itemId, versionId);
+ }
+
+ @Override
+ public ItemVersionConflict getVersionConflict(SessionContext context, Id itemId, Id versionId) {
+ return connector.getVersionConflict(context, itemId, versionId);
+ }
+
+ @Override
+ public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, ItemVersionData itemVersionData) {
+ return connector.createVersion(context, itemId, baseVersionId, itemVersionData);
+ }
+
+ @Override
+ public void updateVersion(SessionContext context, Id itemId, Id versionId, ItemVersionData itemVersionData) {
+ connector.updateVersion(context, itemId, versionId, itemVersionData);
+ }
+
+ @Override
+ public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) {
+ connector.tagVersion(context, itemId, versionId, tag);
+ }
+
+ @Override
+ public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) {
+ connector.resetVersionHistory(context, itemId, versionId, changeRef);
+ }
+
+ @Override
+ public void publishVersion(SessionContext context, Id itemId, Id versionId, String message) {
+ connector.publishVersion(context, itemId, versionId, message);
+ }
+
+ @Override
+ public void syncVersion(SessionContext context, Id itemId, Id versionId) {
+ connector.syncVersion(context, itemId, versionId);
+ }
+
+ @Override
+ public void forceSyncVersion(SessionContext context, Id itemId, Id versionId) {
+ connector.forceSyncVersion(context, itemId, versionId);
+ }
+
+ @Override
+ public void cleanVersion(SessionContext context, Id itemId, Id versionId) {
+ connector.cleanVersion(context, itemId, versionId);
+ }
+
+ @Override
+ public void revert(SessionContext context, Id itemId, Id versionId, Id revisionId) {
+ connector.revertVersionRevision(context, itemId, versionId, revisionId);
+ }
+
+ @Override
+ public ItemVersionRevisions listRevisions(SessionContext context, Id itemId, Id versionId) {
+ return connector.listVersionRevisions(context, itemId, versionId);
+ }
+
+ @Override
+ public Collection<HealthInfo> checkHealth(SessionContext context) {
+ return connector.checkHealth(context);
+ }
+
+ @Override
+ public String getVersion(SessionContext context) {
+ return connector.getVersion(context);
+ }
}