bjoern@416: /* bjoern@416: * Copyright (c) 2011 by Intevation GmbH bjoern@416: * bjoern@416: * This program is free software under the LGPL (>=v2.1) bjoern@416: * Read the file LGPL.txt coming with the software for details bjoern@416: * or visit http://www.gnu.org/licenses/ if it does not exist. bjoern@416: */ bjoern@416: package de.intevation.artifactdatabase.rest; bjoern@416: bjoern@416: import java.io.IOException; bjoern@416: bjoern@416: import org.apache.log4j.Logger; bjoern@416: bjoern@416: import org.restlet.data.MediaType; bjoern@416: import org.restlet.data.Status; bjoern@416: import org.restlet.ext.xml.DomRepresentation; bjoern@416: import org.restlet.representation.EmptyRepresentation; bjoern@416: import org.restlet.representation.Representation; bjoern@416: import org.restlet.resource.ResourceException; bjoern@416: import org.restlet.Response; bjoern@416: bjoern@416: import org.w3c.dom.Document; bjoern@416: bjoern@416: import de.intevation.artifacts.ArtifactDatabase; bjoern@416: import de.intevation.artifacts.ArtifactDatabaseException; bjoern@416: bjoern@416: /** bjoern@416: * A Rest resource that finds the user provided by the artifact database. bjoern@416: * bjoern@416: */ bjoern@416: public class FindUserResource bjoern@416: extends BaseResource bjoern@416: { bjoern@416: /** The logger that is used in this class.*/ bjoern@416: private static Logger logger = Logger.getLogger(FindUserResource.class); bjoern@416: bjoern@416: /** server URL where to reach the resource.*/ bjoern@416: public static final String PATH = "/find-user"; bjoern@416: bjoern@416: bjoern@416: @Override bjoern@416: protected Representation innerPost(Representation requestRepr) bjoern@416: throws ResourceException bjoern@416: { bjoern@416: Document input = null; bjoern@416: bjoern@416: try { bjoern@416: DomRepresentation in = new DomRepresentation(requestRepr); bjoern@416: in.setNamespaceAware(true); bjoern@416: input = in.getDocument(); bjoern@416: } bjoern@416: catch (IOException ioe) { bjoern@416: logger.error(ioe.getLocalizedMessage(), ioe); bjoern@416: bjoern@416: Response response = getResponse(); bjoern@416: response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ioe); bjoern@416: return new EmptyRepresentation(); bjoern@416: } bjoern@416: bjoern@416: ArtifactDatabase db = getArtifactDatabase(); bjoern@416: bjoern@416: try { bjoern@416: logger.info(PATH); bjoern@416: bjoern@416: return new DomRepresentation( bjoern@416: MediaType.APPLICATION_XML, bjoern@416: db.findUser(input, getCallMeta())); bjoern@416: } bjoern@416: catch (ArtifactDatabaseException adbe) { bjoern@416: logger.warn(adbe.getLocalizedMessage(), adbe); bjoern@416: bjoern@416: Response response = getResponse(); bjoern@416: response.setStatus( bjoern@416: Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, adbe.getMessage()); bjoern@416: return new EmptyRepresentation(); bjoern@416: } bjoern@416: } bjoern@416: } bjoern@416: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :