/*
 * Copyright 2015-2017 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opencb.opencga.catalog.db.mongodb.converters;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document;
import org.opencb.commons.datastore.mongodb.GenericDocumentComplexConverter;
import org.opencb.opencga.core.common.JacksonUtils;
import org.opencb.opencga.core.models.Panel;

import java.io.IOException;
import java.io.UncheckedIOException;

/**
 * Created by pfurio on 01/06/16.
 */
public class PanelConverter extends GenericDocumentComplexConverter<Panel> {

    public PanelConverter() {
        super(Panel.class);
    }

    @Override
    public Document convertToStorageType(Panel object) {
        try {
            String json = JacksonUtils.getDefaultObjectMapper().writeValueAsString(object);
            Document document = Document.parse(json);
            replaceDots(document);
            document.put("uid", object.getUid());
            document.put("studyUid", object.getStudyUid());
            return document;
        } catch (JsonProcessingException e) {
            throw new UncheckedIOException(e);
        }
    }

    @Override
    public Panel convertToDataModelType(Document document) {
        try {
            restoreDots(document);
            String json = JacksonUtils.getDefaultObjectMapper().writeValueAsString(document);
            return JacksonUtils.getDefaultObjectMapper().readValue(json, Panel.class);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}

@@ -652,67 +652,8 @@
 s;%0A%0A
-import com.fasterxml.jackson.core.JsonProcessingException;%0A
 impo
@@ -853,74 +853,8 @@
 l;%0A%0A
-import java.io.IOException;%0Aimport java.io.UncheckedIOException;%0A%0A
 /**%0A
@@ -1020,24 +1020,63 @@
 (Panel.class
+, JacksonUtils.getDefaultObjectMapper()
 );%0A    %7D%0A%0A  
@@ -1156,191 +1156,60 @@
     
-try %7B%0A            String json = JacksonUtils.getDefaultObjectMapper().writeValueAsString(object);%0A            Document document = Document.parse(json);%0A            replaceDots(documen
+Document document = super.convertToStorageType(objec
 t);%0A
@@ -1208,36 +1208,32 @@
 bject);%0A        
- 
-   
 document.put(%22ui
@@ -1246,36 +1246,32 @@
 ject.getUid());%0A
-    
         document
@@ -1306,28 +1306,24 @@
 tudyUid());%0A
-    
         retu
@@ -1343,514 +1343,9 @@
     
-    %7D catch (JsonProcessingException e) %7B%0A            throw new UncheckedIOException(e);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Panel convertToDataModelType(Document document) %7B%0A        try %7B%0A            restoreDots(document);%0A            String json = JacksonUtils.getDefaultObjectMapper().writeValueAsString(document);%0A            return JacksonUtils.getDefaultObjectMapper().readValue(json, Panel.class);%0A        %7D catch (IOException e) %7B%0A            throw new UncheckedIOException(e);%0A        %7D%0A    
 %7D
+%0A
 %0A%7D%0A

improve PanelConverter to use the converter implemented in java common libs