aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/dao/impl/zusammen/convertor/ElementToComponentMonitoringUploadConvertor.java
blob: dd3d122560353c2e855b0a9f5d6756de8ef677a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor;

import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
import com.amdocs.zusammen.datatypes.item.Info;
import org.openecomp.convertor.ElementConvertor;
import org.openecomp.core.enrichment.types.MonitoringUploadType;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity;

import java.nio.ByteBuffer;

import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor.ElementToProcessConvertor.ARTIFACT_NAME;

public class ElementToComponentMonitoringUploadConvertor extends ElementConvertor<ComponentMonitoringUploadEntity> {

  @Override
  public ComponentMonitoringUploadEntity convert(Element element) {
    ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity();

    mibEntity.setId(element.getElementId().getValue());
    mibEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData())));
    mapInfoToComponentMonitoringUploadEntity(mibEntity, element.getInfo());
    return mibEntity;
  }

  @Override
  public ComponentMonitoringUploadEntity convert(ElementInfo elementInfo) {
    ComponentMonitoringUploadEntity mibEntity = new ComponentMonitoringUploadEntity();

    mibEntity.setId(elementInfo.getId().getValue());
    mapInfoToComponentMonitoringUploadEntity(mibEntity, elementInfo.getInfo());
    return mibEntity;
  }


  public void mapInfoToComponentMonitoringUploadEntity(ComponentMonitoringUploadEntity mibEntity,
                                                       Info info) {

    mibEntity.setArtifactName((String) info.getProperties().get(ARTIFACT_NAME));
    mibEntity.setType(MonitoringUploadType.valueOf(info.getName()));
  }


}