diff options
author | 2017-02-19 12:35:04 +0200 | |
---|---|---|
committer | 2017-02-19 12:35:04 +0200 | |
commit | f5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch) | |
tree | 72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main | |
parent | 451a3400b76511393c62a444f588a4ed15f4a549 (diff) |
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main')
22 files changed, 1857 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoCassandraImpl.java new file mode 100644 index 0000000000..2525537cef --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoCassandraImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + + +import java.nio.ByteBuffer; +import java.util.Collection; + +public class ComponentArtifactDaoCassandraImpl extends CassandraBaseDao<ComponentArtifactEntity> + implements ComponentArtifactDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final ComponentArtifactAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ComponentArtifactAccessor.class); + private static final Mapper<ComponentArtifactEntity> mapper = + noSqlDb.getMappingManager().mapper(ComponentArtifactEntity.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + // metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata + // (VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, + // Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), mapper + // .getTableMetadata().getPartitionKey().get(1).getName(), "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + public ComponentArtifactEntity getArtifactByType(ComponentArtifactEntity entity) { + return accessor.listByType(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getType().toString()).one(); + } + + @Override + protected Mapper<ComponentArtifactEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(ComponentArtifactEntity entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getType().toString(), entity.getId()}; + } + + @Override + public Collection<ComponentArtifactEntity> list(ComponentArtifactEntity entity) { + return accessor.listByType(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getType().toString()).all(); + } + + @Override + public void update(ComponentArtifactEntity entity) { + accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId(), entity.getArtifactName(), entity.getArtifact(), + entity.getType().toString()); + + } + + @Override + public void delete(ComponentArtifactEntity entity) { + accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getType().toString()); + } + + @Override + public Collection<ComponentArtifactEntity> getArtifactNamesAndTypesForComponent( + ComponentArtifactEntity entity) { + return accessor.getArtifactNamesAndTypesForComponent(entity.getVspId(), + versionMapper.toUDT(entity.getVersion()), entity.getComponentId()).all(); + } + + @Override + public void deleteAll(ComponentArtifactEntity entity) { + accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion())); + } + + + @Accessor + interface ComponentArtifactAccessor { + + @Query( + "insert into vsp_component_artifact (vsp_id, version, component_id, artifact_id, name, " + + "artifact, artifact_type) values (?,?,?,?,?,?,?)") + ResultSet update(String vspId, UDTValue version, String componentId, String id, + String artifactName, ByteBuffer artifact, String type); + + @Query( + "select vsp_id, version, component_id, artifact_type, artifact_id, name, artifact from " + + "vsp_component_artifact where vsp_id=? and version=? and component_id=? and " + + "artifact_type =?") + Result<ComponentArtifactEntity> listByType(String vspId, UDTValue version, String componentId, + String type); + + @Query( + "delete name, artifact from vsp_component_artifact where vsp_id=? and version=? and " + + "component_id=? and artifact_type=? and artifact_id=?") + ResultSet delete(String vspId, UDTValue version, String componentId, String type, + String artifactId); + + @Query( + "delete from vsp_component_artifact where vsp_id=? and version=? and component_id=? " + + "and artifact_type=?") + ResultSet delete(String vspId, UDTValue version, String componentId, String artifactType); + + @Query("delete from vsp_component_artifact where vsp_id=? and version=?") + ResultSet deleteAll(String vspId, UDTValue version); + + @Query( + "select name, artifact_type from vsp_component_artifact where vsp_id=? and version=? " + + "and component_id=?") + Result<ComponentArtifactEntity> getArtifactNamesAndTypesForComponent(String vspId, + UDTValue version, + String componentId); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoFactoryImpl.java new file mode 100644 index 0000000000..07a9f104f4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentArtifactDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory; + +public class ComponentArtifactDaoFactoryImpl extends ComponentArtifactDaoFactory { + private static final ComponentArtifactDao INSTANCE = new ComponentArtifactDaoCassandraImpl(); + + @Override + public ComponentArtifactDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoCassandraImpl.java new file mode 100644 index 0000000000..85372380c0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoCassandraImpl.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.UniqueValueMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class ComponentDaoCassandraImpl extends CassandraBaseDao<ComponentEntity> + implements ComponentDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<ComponentEntity> mapper = + noSqlDb.getMappingManager().mapper(ComponentEntity.class); + private static final ComponentAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ComponentAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + + metadata.setUniqueValuesMetadata(Collections.singletonList( + new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.COMPONENT_NAME, + Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + protected Mapper<ComponentEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(ComponentEntity entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getId()}; + } + + @Override + public void update(ComponentEntity entity) { + accessor.updateCompositionData(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getId(), entity.getCompositionData()); + } + + @Override + public Collection<ComponentEntity> list(ComponentEntity entity) { + return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all(); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String id, + String questionnaireData) { + accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id); + } + + @Override + public Collection<ComponentEntity> listQuestionnaires(String vspId, Version version) { + return accessor.listQuestionnaires(vspId, versionMapper.toUDT(version)).all(); + } + + @Override + public void deleteAll(String vspId, Version version) { + accessor.deleteAll(vspId, version); + } + + @Accessor + interface ComponentAccessor { + + @Query( + "select vsp_id, version, component_id, composition_data from vsp_component " + + "where vsp_id=? and version=?") + Result<ComponentEntity> list(String vspId, UDTValue version); + + @Query( + "select vsp_id, version, component_id, questionnaire_data from vsp_component " + + "where vsp_id=? and version=?") + Result<ComponentEntity> listQuestionnaires(String vspId, UDTValue version); + + @Query( + "insert into vsp_component (vsp_id, version, component_id, composition_data) " + + "values (?,?,?,?)") + ResultSet updateCompositionData(String vspId, UDTValue version, String id, + String compositionData); + + @Query( + "update vsp_component set questionnaire_data=? where vsp_id=? and version=? " + + "and component_id=?") + ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version, + String id); + + @Query("delete from vsp_component where vsp_id=? and version=?") + ResultSet deleteAll(String vspId, Version version); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoFactoryImpl.java new file mode 100644 index 0000000000..1e57242ce1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ComponentDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; + +public class ComponentDaoFactoryImpl extends ComponentDaoFactory { + private static final ComponentDao INSTANCE = new ComponentDaoCassandraImpl(); + + @Override + public ComponentDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoCassandraImpl.java new file mode 100644 index 0000000000..f7b8f30f0a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoCassandraImpl.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.UniqueValueMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class NetworkDaoCassandraImpl extends CassandraBaseDao<NetworkEntity> implements NetworkDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<NetworkEntity> mapper = + noSqlDb.getMappingManager().mapper(NetworkEntity.class); + private static final NetworkAccessor accessor = + noSqlDb.getMappingManager().createAccessor(NetworkAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + + metadata.setUniqueValuesMetadata(Collections.singletonList( + new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.NETWORK_NAME, + Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + protected Mapper<NetworkEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(NetworkEntity entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getId()}; + } + + @Override + public void update(NetworkEntity entity) { + accessor.updateCompositionData(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getId(), entity.getCompositionData()); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String id, + String questionnaireData) { + accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id); + } + + @Override + public Collection<NetworkEntity> list(NetworkEntity entity) { + return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all(); + } + + @Override + public void deleteAll(String vspId, Version version) { + accessor.deleteAll(vspId, version); + } + + @Accessor + interface NetworkAccessor { + + @Query( + "select vsp_id, version, network_id, composition_data from vsp_network where vsp_id=? " + + "and version=?") + Result<NetworkEntity> list(String vspId, UDTValue version); + + @Query( + "insert into vsp_network (vsp_id, version, network_id, composition_data) values (?,?,?,?)") + ResultSet updateCompositionData(String vspId, UDTValue version, String id, + String compositionData); + + @Query( + "update vsp_network set questionnaire_data=? where vsp_id=? and version=? and network_id=?") + ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version, + String id); + + @Query("delete from vsp_network where vsp_id=? and version=?") + ResultSet deleteAll(String vspId, Version version); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoFactoryImpl.java new file mode 100644 index 0000000000..b4360996df --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NetworkDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; + +public class NetworkDaoFactoryImpl extends NetworkDaoFactory { + private static final NetworkDao INSTANCE = new NetworkDaoCassandraImpl(); + + @Override + public NetworkDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoCassandraImpl.java new file mode 100644 index 0000000000..e7e1eed8e0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoCassandraImpl.java @@ -0,0 +1,148 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.UniqueValueMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class NicDaoCassandraImpl extends CassandraBaseDao<NicEntity> implements NicDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<NicEntity> mapper = + noSqlDb.getMappingManager().mapper(NicEntity.class); + private static final NicAccessor accessor = + noSqlDb.getMappingManager().createAccessor(NicAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + + metadata.setUniqueValuesMetadata(Collections + .singletonList(new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.NIC_NAME, + Arrays.asList("vsp_id", "version", "component_id", "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + protected Mapper<NicEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(NicEntity entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId()}; + } + + @Override + public void create(NicEntity entity) { + super.create(entity); + } + + @Override + public void update(NicEntity entity) { + accessor.updateCompositionData(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId(), entity.getCompositionData()); + } + + @Override + public void updateQuestionnaireData(String vspId, Version version, String id, String componentId, + String questionnaireData) { + accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id, + componentId); + } + + @Override + public Collection<NicEntity> listByVsp(String vspId, Version version) { + return accessor.listByVspId(vspId, versionMapper.toUDT(version)).all(); + } + + @Override + public Collection<NicEntity> list(NicEntity entity) { + return accessor.listByComponentId(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId()).all(); + } + + public void deleteByComponentId(String vspId, Version version, String componentId) { + accessor.deleteByComponentId(vspId, version, componentId); + } + + public void deleteByVspId(String vspId, Version version) { + accessor.deleteByVspId(vspId, versionMapper.toUDT(version)); + } + + @Accessor + interface NicAccessor { + + @Query( + "select vsp_id, version, component_id, nic_id, composition_data " + + "from vsp_component_nic where vsp_id=? and version=? and component_id=?") + Result<NicEntity> listByComponentId(String vspId, UDTValue version, String componentId); + + @Query("select * from vsp_component_nic where vsp_id=? and version=?") + Result<NicEntity> listByVspId(String vspId, UDTValue version); + + @Query( + "insert into vsp_component_nic (vsp_id, version, component_id, nic_id, composition_data) " + + "values (?,?,?,?,?)") + ResultSet updateCompositionData(String vspId, UDTValue version, String componentId, String id, + String compositionData); + + @Query( + "update vsp_component_nic set questionnaire_data=? where vsp_id=? and version=? " + + "and component_id=? and nic_id=?") + ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version, + String componentId, String id); + + @Query("delete from vsp_component_nic where vsp_id=? and version=? and component_id=?") + ResultSet deleteByComponentId(String vspId, Version version, String componentId); + + @Query("delete from vsp_component_nic where vsp_id=? and version=?") + ResultSet deleteByVspId(String vspId, UDTValue version); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoFactoryImpl.java new file mode 100644 index 0000000000..f4dd8d5a71 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/NicDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; + +public class NicDaoFactoryImpl extends NicDaoFactory { + private static final NicDao INSTANCE = new NicDaoCassandraImpl(); + + @Override + public NicDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoFactoryImpl.java new file mode 100644 index 0000000000..8b9bedcd3a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; + +public class PackageInfoDaoFactoryImpl extends PackageInfoDaoFactory { + private static final PackageInfoDao INSTANCE = new PackageInfoDaoImpl(); + + @Override + public PackageInfoDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoImpl.java new file mode 100644 index 0000000000..9b7b81fe52 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/PackageInfoDaoImpl.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class PackageInfoDaoImpl extends CassandraBaseDao<PackageInfo> implements PackageInfoDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<PackageInfo> mapper = + noSqlDb.getMappingManager().mapper(PackageInfo.class); + private static final PackageInfoAccessor accessor = + noSqlDb.getMappingManager().createAccessor(PackageInfoAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + protected Mapper<PackageInfo> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(PackageInfo entity) { + return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion())}; + } + + @Override + public Collection<PackageInfo> list(PackageInfo entity) { + return accessor.listInfo().all(); + } + + @Override + public List<PackageInfo> listByCategory(String category, String subCategory) { + Result<PackageInfo> packages = accessor.listInfo(); + + List<PackageInfo> filteredPackages = new ArrayList<>(); + for (PackageInfo packageInfo : packages) { + if (category != null) { + if (category.equals(packageInfo.getCategory())) { + filteredPackages.add(packageInfo); + } + } else if (subCategory != null) { + if (subCategory.equals(packageInfo.getSubCategory())) { + filteredPackages.add(packageInfo); + } + } else { + filteredPackages.add(packageInfo); + } + } + + return filteredPackages; + } + + @Override + public void deleteRowTranslateContent(String vspId, Version version) { + accessor.deleteRowTranslateContent(vspId, version); + } + + @Accessor + interface PackageInfoAccessor { + + @Query( + "SELECT vsp_id,version,display_name,vsp_name,vsp_description,vendor_name,category," + + "sub_category,vendor_release,package_checksum,package_type FROM package_details") + Result<PackageInfo> listInfo(); + + @Query("DELETE TRANSLATE_CONTENT FROM package_details WHERE vsp_id=? and version=?") + Result<PackageInfo> deleteRowTranslateContent(String vspId, Version version); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoCassandraImpl.java new file mode 100644 index 0000000000..0e9fd90a13 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoCassandraImpl.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.nio.ByteBuffer; + +public class ProcessArtifactDaoCassandraImpl implements ProcessArtifactDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final ProcessArtifactAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ProcessArtifactAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void update(ProcessArtifactEntity entity) { + accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId(), entity.getArtifactName(), entity.getArtifact()); + } + + @Override + public ProcessArtifactEntity get(ProcessArtifactEntity entity) { + return accessor + .get(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId(), + entity.getId()); + } + + @Override + public void delete(ProcessArtifactEntity entity) { + accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId()); + } + + @Accessor + interface ProcessArtifactAccessor { + + @Query( + "insert into vsp_process (vsp_id, version, component_id, process_id, artifact_name," + + " artifact) values (?,?,?,?,?,?)") + ResultSet update(String vspId, UDTValue version, String componentId, String id, + String artifactName, ByteBuffer artifact); + + @Query( + "select vsp_id, version, component_id, process_id, artifact_name, artifact " + + "from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") + ProcessArtifactEntity get(String vspId, UDTValue version, String componentId, String id); + + @Query( + "delete artifact_name, artifact from vsp_process where vsp_id=? and version=? and" + + " component_id=? and process_id=?") + ResultSet delete(String vspId, UDTValue version, String componentId, String id); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoFactoryImpl.java new file mode 100644 index 0000000000..2a5d9013bd --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessArtifactDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDaoFactory; + +public class ProcessArtifactDaoFactoryImpl extends ProcessArtifactDaoFactory { + private static final ProcessArtifactDao INSTANCE = new ProcessArtifactDaoCassandraImpl(); + + @Override + public ProcessArtifactDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoCassandraImpl.java new file mode 100644 index 0000000000..b8900eb5d3 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoCassandraImpl.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.UniqueValueMetadata; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +public class ProcessDaoCassandraImpl implements ProcessDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<ProcessEntity> mapper = + noSqlDb.getMappingManager().mapper(ProcessEntity.class); + private static final ProcessAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ProcessAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersionableEntityMetadata metadata = new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName()); + + metadata.setUniqueValuesMetadata(Collections.singletonList( + new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME, + Arrays.asList("vsp_id", "version", "component_id", "name")))); + + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, metadata); + } + + @Override + public Collection<ProcessEntity> list(ProcessEntity entity) { + return accessor + .list(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId()) + .all(); + } + + @Override + public void create(ProcessEntity entity) { + accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription()); + } + + @Override + public void update(ProcessEntity entity) { + accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription()); + } + + @Override + public ProcessEntity get(ProcessEntity entity) { + return accessor + .get(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId(), + entity.getId()); + } + + @Override + public void delete(ProcessEntity entity) { + if (entity.getId() == null) { + accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId()); + } else { + accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), + entity.getComponentId(), entity.getId()); + } + } + + public void deleteAll(ProcessEntity entity) { + accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion())); + } + + @Accessor + interface ProcessAccessor { + + @Query( + "insert into vsp_process (vsp_id, version, component_id, process_id, name, description) " + + "values (?,?,?,?,?,?)") + ResultSet update(String vspId, UDTValue version, String componentId, String id, String name, + String description); + + @Query( + "select vsp_id, version, component_id, process_id, name, description, artifact_name " + + "from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") + ProcessEntity get(String vspId, UDTValue version, String componentId, String id); + + @Query( + "select vsp_id, version, component_id, process_id, name, description, artifact_name " + + "from vsp_process where vsp_id=? and version=? and component_id=?") + Result<ProcessEntity> list(String vspId, UDTValue version, String componentId); + + @Query( + "delete from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?") + ResultSet delete(String vspId, UDTValue version, String componentId, String id); + + @Query("delete from vsp_process where vsp_id=? and version=? and component_id=?") + ResultSet deleteAll(String vspId, UDTValue version, String componentId); + + @Query("delete from vsp_process where vsp_id=? and version=?") + ResultSet deleteAll(String vspId, UDTValue version); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoFactoryImpl.java new file mode 100644 index 0000000000..4c981d8448 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/ProcessDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; + +public class ProcessDaoFactoryImpl extends ProcessDaoFactory { + private static final ProcessDao INSTANCE = new ProcessDaoCassandraImpl(); + + @Override + public ProcessDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoFactoryImpl.java new file mode 100644 index 0000000000..317bc344c4 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDaoFactory; + +public class UploadDataDaoFactoryImpl extends UploadDataDaoFactory { + private static final UploadDataDao INSTANCE = new UploadDataDaoImpl(); + + @Override + public UploadDataDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoImpl.java new file mode 100644 index 0000000000..df019a4f53 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/UploadDataDaoImpl.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.nio.ByteBuffer; +import java.util.Collection; + +public class UploadDataDaoImpl extends CassandraBaseDao<UploadDataEntity> implements UploadDataDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<UploadDataEntity> mapper = + noSqlDb.getMappingManager().mapper(UploadDataEntity.class); + private static final UploadDataAccessor accessor = + noSqlDb.getMappingManager().createAccessor(UploadDataAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + protected Mapper<UploadDataEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(UploadDataEntity entity) { + return new Object[]{entity.getId(), versionMapper.toUDT(entity.getVersion())}; + } + + @Override + public Collection<UploadDataEntity> list(UploadDataEntity entity) { + return accessor.listAll().all(); + } + + @Override + public void deleteContentDataAndValidationData(String vspId, Version version) { + accessor.deleteContentDataAndValidationData(vspId, versionMapper.toUDT(version)); + } + + @Override + public ByteBuffer getContentData(String vspId, Version version) { + return accessor.getContentData(vspId, version).one().getContentData(); + } + + + @Accessor + interface UploadDataAccessor { + + @Query( + "SELECT package_name, package_version, content_data, validation_data FROM vsp_information") + Result<UploadDataEntity> listAll(); + + @Query( + "DELETE package_name, package_version, content_data, validation_data FROM vsp_information " + + "WHERE vsp_id=? and version=?") + Result<VspDetails> deleteContentDataAndValidationData(String vspId, UDTValue udtValue); + + @Query("SELECT CONTENT_DATA FROM vsp_information WHERE vsp_id=? and version=?") + Result<UploadDataEntity> getContentData(String vspId, Version version); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoFactoryImpl.java new file mode 100644 index 0000000000..587f8ac036 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; + +public class VendorSoftwareProductDaoFactoryImpl extends VendorSoftwareProductDaoFactory { + private static final VendorSoftwareProductDao INSTANCE = new VendorSoftwareProductDaoImpl(); + + @Override + public VendorSoftwareProductDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoImpl.java new file mode 100644 index 0000000000..f592e63280 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductDaoImpl.java @@ -0,0 +1,349 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.core.model.dao.EnrichedServiceArtifactDao; +import org.openecomp.core.model.dao.EnrichedServiceArtifactDaoFactory; +import org.openecomp.core.model.dao.ServiceArtifactDaoFactory; +import org.openecomp.core.model.dao.ServiceArtifactDaoInter; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessArtifactDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.UploadDataDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentArtifactEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessArtifactEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.List; +import java.util.Objects; + +public class VendorSoftwareProductDaoImpl implements VendorSoftwareProductDao { + + private static final VendorSoftwareProductInfoDao vspInfoDao = + VendorSoftwareProductInfoDaoFactory.getInstance().createInterface(); + private static final PackageInfoDao packageInfoDao = + PackageInfoDaoFactory.getInstance().createInterface(); + private static final UploadDataDao uploadDataDao = + UploadDataDaoFactory.getInstance().createInterface(); + private static final VspQuestionnaireDao vspQuestionnaireDao = + VspQuestionnaireDaoFactory.getInstance().createInterface(); + private static final NetworkDao networkDao = NetworkDaoFactory.getInstance().createInterface(); + private static final ComponentDao componentDao = + ComponentDaoFactory.getInstance().createInterface(); + private static final NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static final ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface(); + private static final ProcessArtifactDao processArtifactDao = + ProcessArtifactDaoFactory.getInstance().createInterface(); + private static final ComponentArtifactDao componentArtifactDao = + ComponentArtifactDaoFactory.getInstance().createInterface(); + private static final ServiceArtifactDaoInter artifactDao = + ServiceArtifactDaoFactory.getInstance().createInterface(); + private static final EnrichedServiceArtifactDao enrichArtifactDao = + EnrichedServiceArtifactDaoFactory.getInstance().createInterface(); + + @Override + public void registerVersioning(String versionableEntityType) { + vspInfoDao.registerVersioning(versionableEntityType); + vspQuestionnaireDao.registerVersioning(versionableEntityType); + networkDao.registerVersioning(versionableEntityType); + componentDao.registerVersioning(versionableEntityType); + nicDao.registerVersioning(versionableEntityType); + processDao.registerVersioning(versionableEntityType); + } + + @Override + public void createVendorSoftwareProductInfo(VspDetails vspDetails) { + vspInfoDao.create(vspDetails); + } + + @Override + public Collection<VspDetails> listVendorSoftwareProductsInfo() { + return vspInfoDao.list(new VspDetails()); + } + + public VspDetails getVendorSoftwareProductInfo(VspDetails vspDetails) { + return vspInfoDao.get(vspDetails); + } + + + @Override + public void updateVendorSoftwareProductInfo(VspDetails vspDetails) { + vspInfoDao.update(vspDetails); + } + + @Override + public void deleteVendorSoftwareProductInfo(VspDetails vspDetails) { + vspInfoDao.delete(vspDetails); + } + + @Override + public void updateUploadData(UploadDataEntity uploadData) { + uploadDataDao.update(uploadData); + } + + @Override + public UploadDataEntity getUploadData(UploadDataEntity uploadData) { + return uploadDataDao.get(uploadData); + } + + @Override + public ByteBuffer getContentData(UploadDataEntity uploadDataEntity) { + return uploadDataDao.getContentData(uploadDataEntity.getId(), uploadDataEntity.getVersion()); + } + + @Override + public void insertPackageDetails(PackageInfo packageInfo) { + packageInfoDao.update(packageInfo); + } + + @Override + public PackageInfo getPackageInfo(PackageInfo packageInfo) { + return packageInfoDao.get(packageInfo); + } + + @Override + public void deletePackageInfo(PackageInfo packageInfo) { + packageInfoDao.delete(packageInfo); + } + + @Override + public Collection<NetworkEntity> listNetworks(String vspId, Version version) { + return networkDao.list(new NetworkEntity(vspId, version, null)); + } + + @Override + public void createNetwork(NetworkEntity network) { + networkDao.create(network); + } + + @Override + public void updateNetwork(NetworkEntity networkEntity) { + networkDao.update(networkEntity); + } + + @Override + public NetworkEntity getNetwork(String vspId, Version version, String networkId) { + return networkDao.get(new NetworkEntity(vspId, version, networkId)); + } + + @Override + public void deleteNetwork(String vspId, Version version) { + NetworkEntity networkEntity = new NetworkEntity(vspId, version, null); + networkDao.delete(networkEntity); + } + + @Override + public List<PackageInfo> listPackages(String category, String subCategory) { + return packageInfoDao.listByCategory(category, subCategory); + } + + + @Override + public Collection<ComponentEntity> listComponents(String vspId, Version version) { + return componentDao.list(new ComponentEntity(vspId, version, null)); + } + + @Override + public void createComponent(ComponentEntity component) { + componentDao.create(component); + } + + @Override + public void updateComponent(ComponentEntity component) { + componentDao.update(component); + } + + @Override + public ComponentEntity getComponent(String vspId, Version version, String componentId) { + return componentDao.get(new ComponentEntity(vspId, version, componentId)); + } + + @Override + public Collection<ComponentEntity> listComponentsQuestionnaire(String vspId, Version version) { + return componentDao.listQuestionnaires(vspId, version); + } + + @Override + public void updateComponentQuestionnaire(String vspId, Version version, String componentId, + String questionnaireData) { + componentDao.updateQuestionnaireData(vspId, version, componentId, questionnaireData); + } + + @Override + public void deleteComponent(String vspId, Version version) { + ComponentEntity componentEntity = new ComponentEntity(vspId, version, null); + componentDao.delete(componentEntity); + } + + @Override + public Collection<ProcessEntity> listProcesses(String vspId, Version version, + String componentId) { + return processDao.list(new ProcessEntity(vspId, version, componentId, null)); + } + + @Override + public void deleteProcesses(String vspId, Version version, String componentId) { + processDao.delete(new ProcessEntity(vspId, version, componentId, null)); + } + + @Override + public ProcessEntity getProcess(String vspId, Version version, String componentId, + String processId) { + return processDao.get(new ProcessEntity(vspId, version, componentId, processId)); + } + + @Override + public void createProcess(ProcessEntity processEntity) { + processDao.create(processEntity); + } + + @Override + public void updateProcess(ProcessEntity processEntity) { + processDao.update(processEntity); + } + + @Override + public void deleteProcess(String vspId, Version version, String componentId, String processId) { + processDao.delete(new ProcessEntity(vspId, version, componentId, processId)); + } + + @Override + public void uploadProcessArtifact(String vspId, Version version, String componentId, + String processId, byte[] artifact, String artifactName) { + ProcessArtifactEntity processArtifact = + new ProcessArtifactEntity(vspId, version, componentId, processId); + processArtifact.setArtifact(ByteBuffer.wrap(artifact)); + processArtifact.setArtifactName(artifactName); + processArtifactDao.update(processArtifact); + } + + @Override + public ProcessArtifactEntity getProcessArtifact(String vspId, Version version, String componentId, + String processId) { + return processArtifactDao + .get(new ProcessArtifactEntity(vspId, version, componentId, processId)); + } + + @Override + public void deleteProcessArtifact(String vspId, Version version, String componentId, + String processId) { + processArtifactDao.delete(new ProcessArtifactEntity(vspId, version, componentId, processId)); + } + + @Override + public VspQuestionnaireEntity getQuestionnaire(String vspId, Version version) { + return vspQuestionnaireDao.get(new VspQuestionnaireEntity(vspId, version)); + } + + @Override + public void updateQuestionnaire(String vspId, Version version, String questionnaireData) { + vspQuestionnaireDao.updateQuestionnaireData(vspId, version, questionnaireData); + } + + @Override + public Collection<NicEntity> listNics(String vspId, Version version, String componentId) { + return nicDao.list(new NicEntity(vspId, version, componentId, null)); + } + + @Override + public void createNic(NicEntity nic) { + nicDao.create(nic); + } + + @Override + public NicEntity getNic(String vspId, Version version, String componentId, String nicId) { + return nicDao.get(new NicEntity(vspId, version, componentId, nicId)); + } + + @Override + public void updateNic(NicEntity nicEntity) { + nicDao.update(nicEntity); + } + + @Override + public void updateNicQuestionnaire(String vspId, Version version, String componentId, + String nicId, String questionnaireData) { + nicDao.updateQuestionnaireData(vspId, version, componentId, nicId, questionnaireData); + } + + @Override + public Collection<NicEntity> listNicsByVsp(String vspId, Version version) { + return nicDao.listByVsp(vspId, version); + } + + @Override + public void deleteNic(String vspId, Version version, String componentId) { + NicEntity nicEntity = new NicEntity(vspId, version, componentId, null); + nicDao.delete(nicEntity); + } + + @Override + public void deleteUploadData(String vspId, Version version) { + networkDao.deleteAll(vspId, version); + nicDao.deleteByVspId(vspId, version); + artifactDao.delete(vspId, version); + enrichArtifactDao.delete(vspId, version); + ComponentArtifactEntity componentArtifactEntity = + new ComponentArtifactEntity(vspId, version, null, null); + ProcessEntity processEntity = new ProcessEntity(vspId, version, null, null); + componentArtifactDao.deleteAll(componentArtifactEntity); + processDao.deleteAll(processEntity); + componentDao.deleteAll(vspId, version); + uploadDataDao.deleteContentDataAndValidationData(vspId, version); + } + + @Override + public void updateVspLatestModificationTime(String vspId, Version version) { + if (Objects.isNull(vspId) || Objects.isNull(version)) { + return; + } + + VspDetails retrieved = getVendorSoftwareProductInfo(new VspDetails(vspId, version)); + updateVendorSoftwareProductInfo(retrieved); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoFactoryImpl.java new file mode 100644 index 0000000000..1dcb3f4c66 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoFactoryImpl.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDaoFactory; + +public class VendorSoftwareProductInfoDaoFactoryImpl extends VendorSoftwareProductInfoDaoFactory { + private static final VendorSoftwareProductInfoDao INSTANCE = + new VendorSoftwareProductInfoDaoImpl(); + + @Override + public VendorSoftwareProductInfoDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoImpl.java new file mode 100644 index 0000000000..c3096dab29 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VendorSoftwareProductInfoDaoImpl.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +import java.util.Collection; + +public class VendorSoftwareProductInfoDaoImpl extends CassandraBaseDao<VspDetails> + implements VendorSoftwareProductInfoDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<VspDetails> mapper = + noSqlDb.getMappingManager().mapper(VspDetails.class); + private static final VendorSoftwareProductInfoAccessor accessor = + noSqlDb.getMappingManager().createAccessor(VendorSoftwareProductInfoAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName())); + } + + @Override + protected Mapper<VspDetails> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(VspDetails entity) { + return new Object[]{entity.getId(), versionMapper.toUDT(entity.getVersion())}; + } + + @Override + public Collection<VspDetails> list(VspDetails entity) { + return accessor.listAll().all(); + } + + @Accessor + interface VendorSoftwareProductInfoAccessor { + + @Query( + "SELECT vsp_id,version,name,description,icon,category,sub_category,vendor_id," + + "vlm_version,license_agreement,feature_groups FROM vsp_information") + Result<VspDetails> listAll(); + + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoCassandraImpl.java new file mode 100644 index 0000000000..ef4dd0de74 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoCassandraImpl.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.UDTValue; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.UDTMapper; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; +import org.openecomp.sdc.versioning.VersioningManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.types.VersionableEntityMetadata; + +public class VspQuestionnaireDaoCassandraImpl implements VspQuestionnaireDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<VspQuestionnaireEntity> mapper = + noSqlDb.getMappingManager().mapper(VspQuestionnaireEntity.class); + private static final VspQuestionnaireAccessor accessor = + noSqlDb.getMappingManager().createAccessor(VspQuestionnaireAccessor.class); + private static final UDTMapper<Version> versionMapper = + noSqlDb.getMappingManager().udtMapper(Version.class); + + @Override + public void registerVersioning(String versionableEntityType) { + VersioningManagerFactory.getInstance().createInterface() + .register(versionableEntityType, new VersionableEntityMetadata( + mapper.getTableMetadata().getName(), + mapper.getTableMetadata().getPartitionKey().get(0).getName(), + mapper.getTableMetadata().getPartitionKey().get(1).getName())); + } + + @Override + public VspQuestionnaireEntity get(VspQuestionnaireEntity entity) { + return mapper.get(entity.getId(), versionMapper.toUDT(entity.getVersion())); + } + + @Override + public void updateQuestionnaireData(String id, Version version, String questionnaireData) { + accessor.updateQuestionnaireData(questionnaireData, id, versionMapper.toUDT(version)); + } + + @Accessor + interface VspQuestionnaireAccessor { + + @Query("update vsp_information set questionnaire_data=? where vsp_id=? and version=?") + ResultSet updateQuestionnaireData(String questionnaireData, String id, UDTValue version); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoFactoryImpl.java new file mode 100644 index 0000000000..aa91302ca2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/VspQuestionnaireDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.dao.impl; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VspQuestionnaireDaoFactory; + +public class VspQuestionnaireDaoFactoryImpl extends VspQuestionnaireDaoFactory { + private static final VspQuestionnaireDao INSTANCE = new VspQuestionnaireDaoCassandraImpl(); + + @Override + public VspQuestionnaireDao createInterface() { + return INSTANCE; + } +} |