Added oparent to sdc main
[sdc.git] / 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 / ElementToProcessConvertor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor;
22
23 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
24 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
25 import com.amdocs.zusammen.datatypes.item.Info;
26 import org.openecomp.convertor.ElementConvertor;
27 import org.openecomp.core.utilities.file.FileUtils;
28 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
29 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType;
30
31 import java.nio.ByteBuffer;
32
33 public class ElementToProcessConvertor extends ElementConvertor<ProcessEntity> {
34
35   public static final String NAME = "name";
36   public static final String ARTIFACT_NAME = "artifactName";
37   public static final String DESCRIPTION = "description";
38   public static final String PROCESS_TYPE = "processType";
39
40   @Override
41   public ProcessEntity convert(Element element) {
42     if (element == null) {
43       return null;
44     }
45     ProcessEntity processEntity = new ProcessEntity();
46     processEntity.setId(element.getElementId().getValue());
47     processEntity.setArtifact(ByteBuffer.wrap(FileUtils.toByteArray(element.getData())));
48     mapInfoToProcessEntity(processEntity, element.getInfo());
49     return processEntity;
50   }
51
52   @Override
53   public ProcessEntity convert(ElementInfo elementInfo) {
54     if (elementInfo == null) {
55       return null;
56     }
57     ProcessEntity processEntity = new ProcessEntity();
58     processEntity.setId(elementInfo.getId().getValue());
59     mapInfoToProcessEntity(processEntity, elementInfo.getInfo());
60     return processEntity;
61   }
62
63   public void mapInfoToProcessEntity(ProcessEntity processEntity, Info info) {
64     processEntity.setName(info.getProperty(NAME));
65     processEntity.setArtifactName(info.getProperty(ARTIFACT_NAME));
66     processEntity.setDescription(info.getProperty(DESCRIPTION));
67     processEntity.setType(info.getProperty
68         (PROCESS_TYPE) != null ? ProcessType.valueOf(info.getProperty
69         (PROCESS_TYPE)) : null);
70   }
71 }