All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.anotheria.anosite.gen.aswizarddata.rest.WizardDefRestResource Maven / Gradle / Ivy

There is a newer version: 4.1.2
Show newest version
/**
 ********************************************************************************
 *** WizardDefRestResource.java                                               ***
 *** generated by AnoSiteGenerator (ASG), Version: 2.6.3                      ***
 *** Copyright (C) 2005 - 2010 Anotheria.net, www.anotheria.net               ***
 *** All Rights Reserved.                                                     ***
 ********************************************************************************
 *** Don't edit this code, if you aren't sure                                 ***
 *** that you do exactly know what you are doing!                             ***
 *** It's better to invest time in the generator, as into the generated code. ***
 ********************************************************************************
 */

package net.anotheria.anosite.gen.aswizarddata.rest;

import java.util.List;
import net.anotheria.anoprise.metafactory.MetaFactory;
import net.anotheria.anoprise.metafactory.MetaFactoryException;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.POST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.codehaus.jettison.json.JSONArray;
import net.anotheria.anosite.gen.shared.util.ParserUtilService;
import net.anotheria.anosite.gen.aswizarddata.data.WizardDef;
import net.anotheria.anosite.gen.aswizarddata.service.IASWizardDataService;
import net.anotheria.anosite.gen.aswizarddata.service.ASWizardDataServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/wizarddef")
public class WizardDefRestResource{

	private static final Logger LOGGER = LoggerFactory.getLogger(WizardDefRestResource.class);
	private IASWizardDataService aswizarddataService;
	private Gson gson;
	private GsonBuilder builder;

	public WizardDefRestResource() {
		builder = new GsonBuilder();
		builder.setPrettyPrinting();
		gson = builder.create();

		try {
			aswizarddataService = MetaFactory.get(IASWizardDataService.class);
		} catch (MetaFactoryException e) {
			LOGGER.error("Unable to create service: I ASWizardDataService", e);
			throw new RuntimeException("Unable to create service", e);
		}
	}

	@GET
	@Produces("application/json;charset=utf-8")
	public Response getObjects() {

		List result = null;
		try {
			result = aswizarddataService.getWizardDefs();
		} catch (ASWizardDataServiceException e) {
			LOGGER.error("Unable to getWizardDefs", e);
			return Response.status(500).build();
		}

		return Response.status(201).entity(gson.toJson(result)).build();
	}

	@GET
	@Path("/{id}")
	@Produces("application/json;charset=utf-8")
	public Response getObject(@PathParam("id") String id) {

		WizardDef result = null;
		try {
			result = aswizarddataService.getWizardDef(id);
		} catch (ASWizardDataServiceException e) {
			LOGGER.error("Unable to getWizardDef by id", e);
			return Response.status(500).build();
		}

		return Response.status(201).entity(gson.toJson(result)).build();
	}

	@POST
	@Consumes("application/json;charset=utf-8")
	public Response createTransferredObject(JSONArray input) {

		try {
			ParserUtilService.getInstance().executeParsingDocuments(input);
		} catch (Exception e) {
			LOGGER.error("Unable to parsing transferred objects", e);
			return Response.status(500).build();
		}
		return Response.status(201).build();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy