
com.formkiq.server.service.dto.ArchiveDTO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of formkiq-server Show documentation
Show all versions of formkiq-server Show documentation
Server-side integration for the FormKiQ ios application
/*
* Copyright (C) 2016 FormKiQ Inc.
*
* 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 com.formkiq.server.service.dto;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.util.StringUtils;
import com.formkiq.server.service.InvalidRequestBodyException;
/**
* Holder of Archive file format data.
*
*/
public class ArchiveDTO {
/** Jackson Object Mapper. */
private Jackson2ObjectMapperBuilder jsonMapper;
/** Workflow Data. */
private String workflowData;
/** Workflow object. */
private Workflow workflow;
/** Map of Form UUID / Form Object. */
private Map forms = new HashMap();
/** Map of Form UUID / Raw String. */
private Map formRaw = new HashMap();
/**
* constructor.
* @param mapper {@link Jackson2ObjectMapperBuilder}
*/
public ArchiveDTO(final Jackson2ObjectMapperBuilder mapper) {
this.jsonMapper = mapper;
}
/**
* Add Form to Archive.
* @param data {@link String}
* @throws IOException IOException
*/
public void addForm(final String data) throws IOException {
Form form = this.jsonMapper.build().readValue(data, Form.class);
this.forms.put(form.getUUID(), form);
this.formRaw.put(form.getUUID(), data);
}
/**
* Add Workflow to Archive.
* @param data {@link String}
* @throws IOException IOException
*/
public void addWorkflow(final String data) throws IOException {
this.workflowData = data;
this.workflow = this.jsonMapper.build().readValue(this.workflowData,
Workflow.class);
}
/**
* Returns Workflow.
* @return {@link Workflow}
*/
public Workflow getWorkflow() {
return this.workflow;
}
/**
* Returns Workflow JSON.
* @return {@link String}
*/
public String getWorkflowJSON() {
if (!StringUtils.isEmpty(this.workflowData)) {
return this.workflowData;
}
throw new InvalidRequestBodyException();
}
/**
* Returns Form JSON.
* @param uuid {@link String}
* @return {@link String}
*/
public String getFormJSON(final String uuid) {
String data = this.formRaw.get(uuid);
if (StringUtils.isEmpty(data)) {
throw new InvalidRequestBodyException();
}
return data;
}
/**
* @return {@link Map}
*/
public Map getForms() {
return this.forms;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy