diff options
Diffstat (limited to 'catalog-dao/src/main/java/org/openecomp/sdc/be/resources')
17 files changed, 461 insertions, 474 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java deleted file mode 100644 index cbac24ad3d..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============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.be.resources.api; - -import fj.data.Either; -import org.openecomp.sdc.be.dao.api.ResourceUploadStatus; -import org.openecomp.sdc.be.resources.data.ESArtifactData; - -/** - * DAO to manage image upload and retrieval. - * - * @author luc boutier - */ -public interface IResourceUploader { - - /** - * Save an artifact in the DAO layer. - * - * @param imageData - */ - ResourceUploadStatus saveArtifact(ESArtifactData artifactData, boolean isReload); - - /** - * Save an artifact in the DAO layer. - * - * @param imageData - */ - ResourceUploadStatus updateArtifact(ESArtifactData artifactData); - - /** - * Get an artifact as a byte array based on the artifact id. - * - * @param id - * The id of the artifact to read. - * @return The artifact as a byte array. - */ - Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id); - - /** - * Delete the given image. - * - * @param id - * Id of the image to delete. - */ - void deleteArtifact(String id); - - /** - * delete all artifacts - */ - public void deleteAllArtifacts(); - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java new file mode 100644 index 0000000000..bf17383c07 --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java @@ -0,0 +1,153 @@ +/*- + * ============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.be.resources.data; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; + +import java.nio.ByteBuffer; +import java.util.Date; + +@Table(keyspace = "sdccomponent", name = "componentcache") +public class ComponentCacheData { + public final static String RRESOURCE_ID_FIELD = "resourceId"; + + public final static String SERVICE_NAME_FIELD = "serviceName"; + public final static String SERVICE_VERSION_FIELD = "serviceVersion"; + public final static String ARTIFACT_NAME_FIELD = "artifactName"; + + public static String delim = ":"; + + @PartitionKey + @Column(name = "id") + private String id; + + @Column + private ByteBuffer data; + + @Column(name = "modification_time") + private Date modificationTime; + + @Column + private String type; + + @Column(name = "is_dirty") + private boolean isDirty; + + @Column(name = "is_zipped") + private boolean isZipped; + + public ComponentCacheData() { + + } + + public ComponentCacheData(String id, byte[] data, Date modificationTime, String type, boolean isDirty, + boolean isZipped) { + super(); + this.id = id; + if (data != null) { + this.data = ByteBuffer.wrap(data.clone()); + } + this.modificationTime = modificationTime; + this.type = type; + this.isDirty = isDirty; + this.isZipped = isZipped; + } + + public ComponentCacheData(String id) { + + this.id = id; + } + + public ComponentCacheData(String artifactId, byte[] data) { + super(); + this.id = artifactId; + if (data != null) { + this.data = ByteBuffer.wrap(data.clone()); + // this.data = data.clone(); + } + } + + public byte[] getDataAsArray() { + if (data != null) { + return data.array(); + } + return null; + } + + public void setDataAsArray(byte[] data) { + if (data != null) { + this.data = ByteBuffer.wrap(data.clone()); + } + } + + public ByteBuffer getData() { + return data; + } + + public void setData(ByteBuffer data) { + if (data != null) { + this.data = data.duplicate(); + } + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Date getModificationTime() { + return modificationTime; + } + + public void setModificationTime(Date modificationTime) { + this.modificationTime = modificationTime; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public boolean getIsDirty() { + return isDirty; + } + + public void setIsDirty(boolean isDirty) { + this.isDirty = isDirty; + } + + public boolean getIsZipped() { + return isZipped; + } + + public void setIsZipped(boolean isZipped) { + this.isZipped = isZipped; + } + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java index 32a6c18d0d..d2612b9db7 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java @@ -20,15 +20,13 @@ package org.openecomp.sdc.be.resources.data; -import com.google.gson.reflect.TypeToken; import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import java.lang.reflect.Type; import java.util.HashMap; -import java.util.List; import java.util.Map; public abstract class ComponentMetadataData extends GraphNode { @@ -42,47 +40,30 @@ public abstract class ComponentMetadataData extends GraphNode { this.componentInstanceCounter = 0; } - @SuppressWarnings("unchecked") - public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition, Map<String, Object> properties) { + public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition, GraphPropertiesDictionaryExtractor extractor) { this(label, metadataDataDefinition); - metadataDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty())); - metadataDataDefinition.setCreationDate((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty())); - metadataDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty())); - metadataDataDefinition.setConformanceLevel((String) properties.get(GraphPropertiesDictionary.CONFORMANCE_LEVEL.getProperty())); - metadataDataDefinition.setIcon((String) properties.get(GraphPropertiesDictionary.ICON.getProperty())); - metadataDataDefinition.setHighestVersion((Boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty())); - metadataDataDefinition.setLastUpdateDate((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty())); - metadataDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty())); - metadataDataDefinition.setState((String) properties.get(GraphPropertiesDictionary.STATE.getProperty())); - List<String> tagsFromJson; - if(properties.get(GraphPropertiesDictionary.TAGS.getProperty()) instanceof List<?>){ - tagsFromJson = (List<String>) properties.get(GraphPropertiesDictionary.TAGS.getProperty()); - } else { - Type listType = new TypeToken<List<String>>() {}.getType(); - tagsFromJson = getGson().fromJson((String) properties.get(GraphPropertiesDictionary.TAGS.getProperty()), listType); - } - metadataDataDefinition.setTags(tagsFromJson); - metadataDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty())); - metadataDataDefinition.setContactId((String) properties.get(GraphPropertiesDictionary.CONTACT_ID.getProperty())); - metadataDataDefinition.setUUID((String) properties.get(GraphPropertiesDictionary.UUID.getProperty())); - metadataDataDefinition.setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty())); - metadataDataDefinition.setSystemName((String) properties.get(GraphPropertiesDictionary.SYSTEM_NAME.getProperty())); - metadataDataDefinition.setIsDeleted((Boolean) properties.get(GraphPropertiesDictionary.IS_DELETED.getProperty())); - metadataDataDefinition.setProjectCode((String) properties.get(GraphPropertiesDictionary.PROJECT_CODE.getProperty())); - metadataDataDefinition.setCsarUUID((String) properties.get(GraphPropertiesDictionary.CSAR_UUID.getProperty())); - metadataDataDefinition.setCsarVersion((String) properties.get(GraphPropertiesDictionary.CSAR_VERSION.getProperty())); - metadataDataDefinition.setImportedToscaChecksum((String) properties.get(GraphPropertiesDictionary.IMPORTED_TOSCA_CHECKSUM.getProperty())); - metadataDataDefinition.setInvariantUUID((String) properties.get(GraphPropertiesDictionary.INVARIANT_UUID.getProperty())); -// metadataDataDefinition.setComponentType(ComponentTypeEnum.valueOf((String) properties.get(GraphPropertyEnum.COMPONENT_TYPE.getProperty()))); - metadataDataDefinition.setArchived((Boolean) properties.get(GraphPropertiesDictionary.IS_ARCHIVED.getProperty())); - metadataDataDefinition.setVspArchived((Boolean) properties.get(GraphPropertiesDictionary.IS_VSP_ARCHIVED.getProperty())); - Object archiveTime = properties.get(GraphPropertiesDictionary.ARCHIVE_TIME.getProperty()); - if (archiveTime instanceof Integer){ - metadataDataDefinition.setArchiveTime(new Long((Integer) archiveTime)); - } else if (archiveTime instanceof Long) { - metadataDataDefinition.setArchiveTime((Long)archiveTime); - } - componentInstanceCounter = (Integer) properties.get(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty()); + metadataDataDefinition.setUniqueId(extractor.getUniqueId()); + metadataDataDefinition.setCreationDate(extractor.getCreationDate()); + metadataDataDefinition.setDescription(extractor.getDescription()); + metadataDataDefinition.setConformanceLevel(extractor.getConformanceLevel()); + metadataDataDefinition.setIcon(extractor.getIcon()); + metadataDataDefinition.setHighestVersion(extractor.isHighestVersion()); + metadataDataDefinition.setLastUpdateDate(extractor.getLastUpdateDate()); + metadataDataDefinition.setName(extractor.getName()); + metadataDataDefinition.setState(extractor.getState()); + metadataDataDefinition.setTags(extractor.getTags()); + metadataDataDefinition.setVersion(extractor.getVersion()); + metadataDataDefinition.setContactId(extractor.getContactId()); + metadataDataDefinition.setUUID(extractor.getUUID()); + metadataDataDefinition.setNormalizedName(extractor.getNormalizedName()); + metadataDataDefinition.setSystemName(extractor.getSystemName()); + metadataDataDefinition.setIsDeleted(extractor.isDeleted()); + metadataDataDefinition.setProjectCode(extractor.getProjectCode()); + metadataDataDefinition.setCsarUUID(extractor.getCsarUuid()); + metadataDataDefinition.setCsarVersion(extractor.getCsarVersion()); + metadataDataDefinition.setImportedToscaChecksum(extractor.getImportedToscaChecksum()); + metadataDataDefinition.setInvariantUUID(extractor.getInvariantUuid()); + componentInstanceCounter = extractor.getInstanceCounter(); } @Override diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java index 97a3ade391..e23b134f44 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java @@ -1,3 +1,4 @@ +package org.openecomp.sdc.be.resources.data; /*- * ============LICENSE_START======================================================= * SDC @@ -7,9 +8,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,8 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdc.be.resources.data; - +import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition; @@ -30,70 +30,78 @@ import java.util.Map; public class ConsumerData extends GraphNode { - private ConsumerDataDefinition consumerDataDefinition; - - public ConsumerData() { - super(NodeTypeEnum.ConsumerCredentials); - consumerDataDefinition = new ConsumerDataDefinition(); - } - - public ConsumerData(ConsumerDataDefinition consumerDataDefinition) { - super(NodeTypeEnum.ConsumerCredentials); - this.consumerDataDefinition = consumerDataDefinition; - - } - - public ConsumerData(Map<String, Object> properties) { - super(NodeTypeEnum.ConsumerCredentials); - consumerDataDefinition = new ConsumerDataDefinition(); - consumerDataDefinition.setConsumerDetailsLastupdatedtime( - (Long) properties.get(GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME.getProperty())); - consumerDataDefinition.setConsumerLastAuthenticationTime( - (Long) properties.get(GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME.getProperty())); - consumerDataDefinition - .setConsumerName((String) properties.get(GraphPropertiesDictionary.CONSUMER_NAME.getProperty())); - consumerDataDefinition.setConsumerPassword( - (String) properties.get(GraphPropertiesDictionary.CONSUMER_PASSWORD.getProperty())); - consumerDataDefinition - .setConsumerSalt((String) properties.get(GraphPropertiesDictionary.CONSUMER_SALT.getProperty())); - consumerDataDefinition.setLastModfierAtuid( - (String) properties.get(GraphPropertiesDictionary.LAST_MODIFIER_USER_ID.getProperty())); - - } - - @Override - public String getUniqueIdKey() { - return GraphPropertiesDictionary.CONSUMER_NAME.getProperty(); - } - - @Override - public String getUniqueId() { - return consumerDataDefinition.getConsumerName(); - } - - public ConsumerDataDefinition getConsumerDataDefinition() { - return consumerDataDefinition; - } - - @Override - public Map<String, Object> toGraphMap() { - Map<String, Object> map = new HashMap<>(); - addIfExists(map, GraphPropertiesDictionary.CONSUMER_NAME, this.consumerDataDefinition.getConsumerName()); - addIfExists(map, GraphPropertiesDictionary.CONSUMER_PASSWORD, - this.consumerDataDefinition.getConsumerPassword()); - addIfExists(map, GraphPropertiesDictionary.CONSUMER_SALT, this.consumerDataDefinition.getConsumerSalt()); - addIfExists(map, GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME, - this.consumerDataDefinition.getConsumerLastAuthenticationTime()); - addIfExists(map, GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME, - this.consumerDataDefinition.getConsumerDetailsLastupdatedtime()); - addIfExists(map, GraphPropertiesDictionary.LAST_MODIFIER_USER_ID, - this.consumerDataDefinition.getLastModfierAtuid()); - - return map; - } - - @Override - public String toString() { - return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]"; - } + private ConsumerDataDefinition consumerDataDefinition; + + public ConsumerData() { + super(NodeTypeEnum.ConsumerCredentials); + consumerDataDefinition = new ConsumerDataDefinition(); + } + + public ConsumerData(ConsumerDataDefinition consumerDataDefinition) { + super(NodeTypeEnum.ConsumerCredentials); + this.consumerDataDefinition = consumerDataDefinition; + + } + + public ConsumerData(Map<String, Object> properties) { + super(NodeTypeEnum.ConsumerCredentials); + consumerDataDefinition = new ConsumerDataDefinition(); + consumerDataDefinition.setConsumerDetailsLastupdatedtime( + (Long) properties.get(GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME.getProperty())); + consumerDataDefinition.setConsumerLastAuthenticationTime( + (Long) properties.get(GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME.getProperty())); + consumerDataDefinition + .setConsumerName((String) properties.get(GraphPropertiesDictionary.CONSUMER_NAME.getProperty())); + consumerDataDefinition.setConsumerPassword( + (String) properties.get(GraphPropertiesDictionary.CONSUMER_PASSWORD.getProperty())); + consumerDataDefinition + .setConsumerSalt((String) properties.get(GraphPropertiesDictionary.CONSUMER_SALT.getProperty())); + consumerDataDefinition.setLastModfierAtuid( + (String) properties.get(GraphPropertiesDictionary.LAST_MODIFIER_USER_ID.getProperty())); + + } + + @Override + public String getUniqueIdKey() { + return GraphPropertiesDictionary.CONSUMER_NAME.getProperty(); + } + + @Override + public String getUniqueId() { + return consumerDataDefinition.getConsumerName(); + } + + public ConsumerDataDefinition getConsumerDataDefinition() { + return consumerDataDefinition; + } + + @Override + public Map<String, Object> toGraphMap() { + Map<String, Object> map = new HashMap<>(); + addIfExists(map, GraphPropertiesDictionary.CONSUMER_NAME, this.consumerDataDefinition.getConsumerName()); + addIfExists(map, GraphPropertiesDictionary.CONSUMER_PASSWORD, + this.consumerDataDefinition.getConsumerPassword()); + addIfExists(map, GraphPropertiesDictionary.CONSUMER_SALT, this.consumerDataDefinition.getConsumerSalt()); + addIfExists(map, GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME, + this.consumerDataDefinition.getConsumerLastAuthenticationTime()); + addIfExists(map, GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME, + this.consumerDataDefinition.getConsumerDetailsLastupdatedtime()); + addIfExists(map, GraphPropertiesDictionary.LAST_MODIFIER_USER_ID, + this.consumerDataDefinition.getLastModfierAtuid()); + + return map; + } + + //added to handle fortify security violation - t avoid printing consumer data to log + @Override + public ImmutablePair<String, Object> getKeyValueIdForLog() { + return new ImmutablePair<>(getUniqueIdKey(), "consumerName"); + } + + @Override + public String toString() { + return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]"; + } } + + diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ESArtifactData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/DAOArtifactData.java index fca13d5f74..64fac358bf 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ESArtifactData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/DAOArtifactData.java @@ -27,14 +27,14 @@ import com.datastax.driver.mapping.annotations.Table; import java.nio.ByteBuffer; @Table(keyspace = "sdcartifact", name = "resources") -public class ESArtifactData { +public class DAOArtifactData { public static final String RRESOURCE_ID_FIELD = "resourceId"; public static final String SERVICE_NAME_FIELD = "serviceName"; public static final String SERVICE_VERSION_FIELD = "serviceVersion"; public static final String ARTIFACT_NAME_FIELD = "artifactName"; - public final static String delim = ":"; + public static String delim = ":"; @PartitionKey @Column(name = "id") @@ -49,16 +49,16 @@ public class ESArtifactData { // private byte[] data; - public ESArtifactData() { + public DAOArtifactData() { } - public ESArtifactData(String id) { + public DAOArtifactData(String id) { this.id = id; } - public ESArtifactData(String artifactId, byte[] data) { + public DAOArtifactData(String artifactId, byte[] data) { super(); this.id = artifactId; if (data != null) { diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java index 77f2d90632..fac80b439d 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.be.resources.data; import com.google.gson.reflect.TypeToken; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor; import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @@ -39,17 +40,11 @@ public class ProductMetadataData extends ComponentMetadataData { super(NodeTypeEnum.Product, metadataDataDefinition); } - public ProductMetadataData(Map<String, Object> properties) { - super(NodeTypeEnum.Product, new ProductMetadataDataDefinition(), properties); - ((ProductMetadataDataDefinition) metadataDataDefinition) - .setFullName((String) properties.get(GraphPropertiesDictionary.FULL_NAME.getProperty())); - Type listType = new TypeToken<List<String>>() { - }.getType(); - List<String> contactsfromJson = getGson() - .fromJson((String) properties.get(GraphPropertiesDictionary.CONTACTS.getProperty()), listType); - ((ProductMetadataDataDefinition) metadataDataDefinition).setContacts(contactsfromJson); - ((ProductMetadataDataDefinition) metadataDataDefinition) - .setIsActive((Boolean) properties.get(GraphPropertiesDictionary.IS_ACTIVE.getProperty())); + public ProductMetadataData(GraphPropertiesDictionaryExtractor extractor) { + super(NodeTypeEnum.Product, new ProductMetadataDataDefinition(), extractor); + ((ProductMetadataDataDefinition) metadataDataDefinition).setFullName(extractor.getFullName()); + ((ProductMetadataDataDefinition) metadataDataDefinition).setContacts(extractor.getContacts()); + ((ProductMetadataDataDefinition) metadataDataDefinition).setIsActive(extractor.isActive()); } @Override diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java index bc7f34c125..ddb3b9883d 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.resources.data; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @@ -38,18 +39,15 @@ public class ResourceMetadataData extends ComponentMetadataData { super(NodeTypeEnum.Resource, metadataDataDefinition); } - public ResourceMetadataData(Map<String, Object> properties) { - super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition(), properties); - ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorName((String) properties.get(GraphPropertiesDictionary.VENDOR_NAME.getProperty())); - ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorRelease((String) properties.get(GraphPropertiesDictionary.VENDOR_RELEASE.getProperty())); - if (properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()) != null) { - ((ResourceMetadataDataDefinition) metadataDataDefinition).setResourceType(ResourceTypeEnum.valueOf((String) properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()))); - } - ((ResourceMetadataDataDefinition) metadataDataDefinition).setAbstract((Boolean) properties.get(GraphPropertiesDictionary.IS_ABSTRACT.getProperty())); - ((ResourceMetadataDataDefinition) metadataDataDefinition).setCost((String) properties.get(GraphPropertiesDictionary.COST.getProperty())); - ((ResourceMetadataDataDefinition) metadataDataDefinition).setLicenseType((String) properties.get(GraphPropertiesDictionary.LICENSE_TYPE.getProperty())); - ((ResourceMetadataDataDefinition) metadataDataDefinition).setToscaResourceName((String) properties.get(GraphPropertiesDictionary.TOSCA_RESOURCE_NAME.getProperty())); - + public ResourceMetadataData(GraphPropertiesDictionaryExtractor extractor) { + super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition(), extractor); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorName(extractor.getVendorName()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorRelease(extractor.getVendorRelease()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setResourceType(extractor.getResourceType()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setAbstract(extractor.isAbstract()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setCost(extractor.getCost()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setLicenseType(extractor.getLicenseType()); + ((ResourceMetadataDataDefinition) metadataDataDefinition).setToscaResourceName(extractor.getToscaResourceName()); } @Override diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java index a50d7ff6c8..01e4ca4eb4 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.resources.data; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; +import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor; import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @@ -36,12 +37,10 @@ public class ServiceMetadataData extends ComponentMetadataData { super(NodeTypeEnum.Service, serviceMetadataDataDefinition); } - public ServiceMetadataData(Map<String, Object> properties) { - super(NodeTypeEnum.Service, new ServiceMetadataDataDefinition(), properties); - ((ServiceMetadataDataDefinition) metadataDataDefinition) - .setProjectCode((String) properties.get(GraphPropertiesDictionary.PROJECT_CODE.getProperty())); - ((ServiceMetadataDataDefinition) metadataDataDefinition).setDistributionStatus( - (String) properties.get(GraphPropertiesDictionary.DISTRIBUTION_STATUS.getProperty())); + public ServiceMetadataData(GraphPropertiesDictionaryExtractor extractor) { + super(NodeTypeEnum.Service, new ServiceMetadataDataDefinition(), extractor); + metadataDataDefinition.setProjectCode(extractor.getProjectCode()); + ((ServiceMetadataDataDefinition) metadataDataDefinition).setDistributionStatus(extractor.getDistributionStatus()); } @Override diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java index 3e2b95b129..4203c9f4d8 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java @@ -25,7 +25,7 @@ import org.openecomp.sdc.common.log.wrappers.Logger; //TODO rename to AuditAction public enum AuditingActionEnum { - // User admininstration + // User administration ADD_USER("AddUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE), UPDATE_USER("UpdateUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE), DELETE_USER("DeleteUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE), diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java index 92e5f4bf2f..57bab5977e 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java @@ -20,20 +20,36 @@ package org.openecomp.sdc.be.resources.data.auditing; -import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent; +import org.openecomp.sdc.common.datastructure.AuditingFieldsKey; + +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; + +public class AuditingGenericEvent { + protected SimpleDateFormat simpleDateFormat; + protected static String dateFormatPattern = "yyyy-MM-dd HH:mm:ss.SSS z"; -public class AuditingGenericEvent extends ESTimeBasedEvent { protected String requestId; protected String serviceInstanceId; protected String action; protected String status; + protected String timestamp; protected String desc; + protected Map<String, Object> fields = new HashMap<>(); + public AuditingGenericEvent() { super(); + simpleDateFormat = new SimpleDateFormat(dateFormatPattern); + simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + this.timestamp = simpleDateFormat.format(new Date()); + fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), this.timestamp); + } public String getRequestId() { @@ -90,4 +106,21 @@ public class AuditingGenericEvent extends ESTimeBasedEvent { } } + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public Map<String, Object> getFields() { + return fields; + } + + public void setFields(Map<String, Object> fields) { + this.fields = fields; + } + + } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java index c6c609b189..2716621cae 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java @@ -49,5 +49,6 @@ public interface AuditingTypesConstants { String GET_CATEGORY_HIERARCHY_EVENT_TYPE = "getcategoryhierarchyevent"; String EXTERNAL_API_EVENT_TYPE = "externalapievent"; String ENVIRONMENT_ENGINE_EVENT_TYPE = "environmentengineevent"; + String FEATURE_TOGGLE_STATE = "featuretogglestate"; } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java index b8d3bdd03f..7635d8f779 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java @@ -36,6 +36,7 @@ import java.util.TimeZone; public class EcompOperationalEnvironmentEvent extends AuditingGenericEvent { @PartitionKey + @Column(name = "operational_environment_id") protected String operationalEnvironmentId; @ClusteringColumn @@ -101,7 +102,7 @@ public class EcompOperationalEnvironmentEvent extends AuditingGenericEvent { return operationalEnvironmentType; } - public void setOperational_environment_type(String operationalEnvironmentType) { + public void setOperationalEnvironmentType(String operationalEnvironmentType) { this.operationalEnvironmentType = operationalEnvironmentType; } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java index 82e1fca9ca..226e0f0588 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java @@ -169,7 +169,7 @@ public class ResourceAdminEvent extends AuditingGenericEvent { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1)); + fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), timestamp1.getTime()); } public String getResourceName() { diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java new file mode 100644 index 0000000000..86bd60a75a --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java @@ -0,0 +1,120 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2020 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.be.resources.data.togglz; + +import com.datastax.driver.mapping.annotations.Column; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; +import org.openecomp.sdc.common.log.wrappers.Logger; +import org.togglz.core.Feature; +import org.togglz.core.repository.FeatureState; + +import java.util.Map; + +@Table(keyspace = AuditingTypesConstants.REPO_KEYSPACE, name = AuditingTypesConstants.FEATURE_TOGGLE_STATE) +public class FeatureToggleEvent { + private static final Logger logger = Logger.getLogger(FeatureToggleEvent.class); + + @PartitionKey + @Column(name = "feature_name") + private String featureName; + + @Column(name = "enabled") + private String enabled; + + @Column(name = "strategy_id") + private String strategyId; + + @Column(name = "parameters") + private String parameters; + + public void setFeatureName(String featureName) { + this.featureName = featureName; + } + + public void setEnabled(String enabled) { + this.enabled = enabled; + } + + public void setStrategyId(String strategyId) { + this.strategyId = strategyId; + } + + public void setParameters(String parameters) { + this.parameters = parameters; + } + + public String getFeatureName() { + return featureName; + } + + public String getEnabled() { + return enabled; + } + + public String getStrategyId() { + return strategyId; + } + + public String getParameters() { + return parameters; + } + + public FeatureToggleEvent() {} + + public FeatureToggleEvent(FeatureState featureState) { + this(); + this.featureName = featureState.getFeature().name(); + this.enabled = String.valueOf(featureState.isEnabled()); + this.strategyId = featureState.getStrategyId(); + this.parameters = Joiner.on(",").withKeyValueSeparator("=").join(featureState.getParameterMap()); + } + + public FeatureState getFeatureState() { + Feature feature = ToggleableFeature.getFeatureByName(featureName); + if (feature == null) { + return null; + } + FeatureState featureState = new FeatureState(feature, Boolean.valueOf(enabled)); + featureState.setStrategyId(strategyId); + + setParameters(featureState); + return featureState; + + } + + private void setParameters(FeatureState featureState) { + try { + Map<String, String> paramMap = Splitter.on(",").withKeyValueSeparator("=").split(parameters); + paramMap.keySet().forEach(p->featureState.setParameter(p, paramMap.get(p))); + } + catch(IllegalArgumentException e) { + logger.warn(EcompLoggerErrorCode.DATA_ERROR, "FeatureToggle", + "FeatureState Object generating", e.getMessage()); + } + } + + +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java index 6d01268434..2fd2c80b02 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * SDC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 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. @@ -18,28 +18,26 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdc.be.resources.data; +package org.openecomp.sdc.be.resources.data.togglz; -import java.util.List; -import java.util.Map; +import org.togglz.core.Feature; +import org.togglz.core.annotation.Label; +import org.togglz.core.context.FeatureContext; -public class ServiceArtifactsDataCollection { +import java.util.Arrays; - private Map<String, List<ESArtifactData>> serviceArtifactDataMap; +public enum ToggleableFeature implements Feature{ + @Label("Default feature") + DEFAULT_FEATURE; - public Map<String, List<ESArtifactData>> getServiceArtifactDataMap() { - return serviceArtifactDataMap; - } - - public void setServiceArtifactDataMap(Map<String, List<ESArtifactData>> serviceArtifactDataMap) { - this.serviceArtifactDataMap = serviceArtifactDataMap; - } - - public List<ESArtifactData> getNodeTemplateArtifacts(String nodeTemplateName) { - if (serviceArtifactDataMap != null && serviceArtifactDataMap.containsKey(nodeTemplateName)) - return serviceArtifactDataMap.get(nodeTemplateName); - else - return null; - } + public static Feature getFeatureByName(String featureName) { + return Arrays.stream(values()). + filter(e -> e.name().equals(featureName)) + .findFirst() + .orElse(null); + } + public boolean isActive() { + return FeatureContext.getFeatureManager().isActive(this); + } } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java deleted file mode 100644 index cae5c47699..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.be.resources.exception; - -import org.openecomp.sdc.be.dao.api.ResourceUploadStatus; -import org.openecomp.sdc.exception.TechnicalException; - -public class ResourceDAOException extends TechnicalException { - - private static final long serialVersionUID = 171917520842336653L; - - private ResourceUploadStatus status; - - public ResourceDAOException(String message, Throwable cause) { - super(message, cause); - } - - public ResourceDAOException(String message) { - super(message); - } - - public ResourceDAOException(ResourceUploadStatus status, String message, Throwable cause) { - super(message, cause); - this.status = status; - } - - public ResourceDAOException(ResourceUploadStatus status, String message) { - super(message); - this.status = status; - } - - public ResourceUploadStatus getStatus() { - return status; - } - - public void setStatus(ResourceUploadStatus status) { - this.status = status; - } - -} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java deleted file mode 100644 index 5b9f548b46..0000000000 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============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.be.resources.impl; - -import fj.data.Either; -import org.openecomp.sdc.be.config.BeEcompErrorManager; -import org.openecomp.sdc.be.config.ConfigurationManager; -import org.openecomp.sdc.be.dao.api.ICatalogDAO; -import org.openecomp.sdc.be.dao.api.ResourceUploadStatus; -import org.openecomp.sdc.be.resources.api.IResourceUploader; -import org.openecomp.sdc.be.resources.data.ESArtifactData; -import org.openecomp.sdc.be.resources.exception.ResourceDAOException; -import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; - -@Component("resource-upload") -public class ResourceUploader implements IResourceUploader { - - private static final String DEFAULT_ARTIFACT_INDEX_NAME = "resources"; - - @Resource - private ICatalogDAO resourceDAO; - private static Logger log = Logger.getLogger(ResourceUploader.class.getName()); - - @PostConstruct - public void init() { - ConfigurationManager configMgr = ConfigurationManager.getConfigurationManager(); - String artifactsIndex = null; - artifactsIndex = configMgr.getConfiguration().getArtifactsIndex(); - if (artifactsIndex == null || artifactsIndex.isEmpty()) { - artifactsIndex = DEFAULT_ARTIFACT_INDEX_NAME; - } - resourceDAO.addToIndicesMap(ESArtifactData.class.getSimpleName().toLowerCase(), artifactsIndex); - } - - public ResourceUploader() { - super(); - } - - public ResourceUploader(ICatalogDAO resourcetDAO) { - super(); - this.resourceDAO = resourcetDAO; - } - - public ICatalogDAO getResourceDAO() { - return resourceDAO; - } - - public void setResourceDAO(ICatalogDAO resourceDAO) { - this.resourceDAO = resourceDAO; - } - - @Override - public ResourceUploadStatus saveArtifact(ESArtifactData artifactData, boolean isReload) { - ResourceUploadStatus status = ResourceUploadStatus.OK; - if (resourceDAO == null) { - BeEcompErrorManager.getInstance() - .logBeInitializationError("Save Artifact - internal object not initialized"); - log.debug("update artifact failed - resourceDAO is null"); - return ResourceUploadStatus.ERROR; - } - - Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = getArtifact(artifactData.getId()); - if (getArtifactStatus.isLeft()) { - status = ResourceUploadStatus.ALREADY_EXIST; - log.debug("ResourceUploadStatus:saveArtifact artifact with id {} already exist.", artifactData.getId()); - if (isReload) { - status = updateArtifact(artifactData, getArtifactStatus.left().value()); - } - } else { - try { - - resourceDAO.writeArtifact(artifactData); - status = ResourceUploadStatus.OK; - - } catch (ResourceDAOException e) { - status = ResourceUploadStatus.ERROR; - BeEcompErrorManager.getInstance().logBeDaoSystemError("Save Artifact to database"); - log.debug("ResourceUploadStatus:saveArtifact failed with exception ", e); - } - - } - - return status; - } - - @Override - public ResourceUploadStatus updateArtifact(ESArtifactData artifactUpdateData) { - ResourceUploadStatus status = ResourceUploadStatus.OK; - if (resourceDAO == null) - return ResourceUploadStatus.ERROR; - - Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = getArtifact(artifactUpdateData.getId()); - if (getArtifactStatus.isRight()) { - status = getArtifactStatus.right().value(); - log.debug("ResourceUploadStatus:updateArtifactt artifact with id {}", artifactUpdateData.getId() - + " not exist."); - } - if (getArtifactStatus.isLeft()) { - status = updateArtifact(artifactUpdateData, getArtifactStatus.left().value()); - } - - return status; - } - - @Override - public Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id) { - if (resourceDAO == null) - return Either.right(ResourceUploadStatus.ERROR); - - return resourceDAO.getArtifact(id); - } - - @Override - public void deleteArtifact(String id) { - if (resourceDAO != null) { - resourceDAO.deleteArtifact(id); - } - - } - - private ResourceUploadStatus updateArtifact(ESArtifactData artifactUpdateData, ESArtifactData existData) { - ResourceUploadStatus status; - - updateData(artifactUpdateData, existData); - - try { - resourceDAO.writeArtifact(artifactUpdateData); - status = ResourceUploadStatus.OK; - - } catch (ResourceDAOException e) { - status = ResourceUploadStatus.ERROR; - log.debug("ResourceUploadStatus:updateArtifact failed with exception ", e); - } - return status; - } - - private void updateData(ESArtifactData artifactUpdateData, ESArtifactData existData) { - - if (artifactUpdateData.getData() == null) { - artifactUpdateData.setData(existData.getData()); - } - - } - - @Override - public void deleteAllArtifacts() { - resourceDAO.deleteAllArtifacts(); - } - -} |