/** {@inheritDoc} */ @Override public void describeGet(MethodInfo mInfo) { mInfo.setIdentifier("ContactsList"); mInfo.setDocumentation("To Retrieve a sorted list of contacts"); RequestInfo requestInfo = new RequestInfo(); ParameterInfo pInfo = createCommonParameter(REQUEST_QUERY_SORT, "Sort query", LAST_NAME); pInfo.getOptions().add(createOptionInfo(FIRST_NAME, "Sort by first name")); pInfo.getOptions().add(createOptionInfo(LAST_NAME, "Sort by last name")); pInfo.getOptions().add(createOptionInfo(MAIL, "Sort by Email")); pInfo.getOptions().add(createOptionInfo(PHONE, "Sort by Phone")); requestInfo.getParameters().add(pInfo); mInfo.setRequest(requestInfo); ResponseInfo response = new ResponseInfo("Current list of contacts"); response.getStatuses().add(Status.SUCCESS_OK); RepresentationInfo repInfo = new RepresentationInfo(MediaType.APPLICATION_XML); repInfo.setXmlElement(CONTACTS); repInfo.setDocumentation("XML List of contacts"); response.getRepresentations().add(repInfo); repInfo = new RepresentationInfo(MediaType.APPLICATION_JSON); repInfo.setXmlElement(CONTACTS); repInfo.setDocumentation("JSON List of contacts"); response.getRepresentations().add(repInfo); mInfo.getResponses().add(response); }
/** * Descibes the GET method in WADL. * * @param info information */ @Override protected final void describeGet(final MethodInfo info) { this.addInfo(info); info.setIdentifier("NameResolver"); info.setDocumentation("Get the object's coordinates from its name and time for planets."); // objecName parameter final List<ParameterInfo> parametersInfo = new ArrayList<ParameterInfo>(); parametersInfo.add( new ParameterInfo( "objectName", true, "String", ParameterStyle.TEMPLATE, "Object name to resolve")); // reference frame parameter final ParameterInfo paramCoordSys = new ParameterInfo( "coordSystem", true, "String", ParameterStyle.TEMPLATE, "Coordinate system in which the output is formated"); final List<OptionInfo> coordsysOption = new ArrayList<OptionInfo>(); final OptionInfo optionEquatorial = new OptionInfo("Equatorial system in ICRS"); optionEquatorial.setValue(CoordinateSystem.EQUATORIAL.name()); coordsysOption.add(optionEquatorial); final OptionInfo optionGalactic = new OptionInfo("Galactic system"); optionGalactic.setValue(CoordinateSystem.GALACTIC.name()); coordsysOption.add(optionGalactic); paramCoordSys.setOptions(coordsysOption); parametersInfo.add(paramCoordSys); // Name resolver parameter final ParameterInfo nameResolverParam = new ParameterInfo( "nameResolver", false, "String", ParameterStyle.QUERY, "The selected name resolver"); final List<OptionInfo> nameResolverOption = new ArrayList<OptionInfo>(); final OptionInfo optionCDS = new OptionInfo("The CDS name resolver based on SIMBAD and NED"); optionCDS.setValue("CDS"); nameResolverOption.add(optionCDS); final OptionInfo optionIAS = new OptionInfo("The IAS name resolver for Corot"); optionIAS.setValue("IAS"); nameResolverOption.add(optionIAS); nameResolverParam.setOptions(nameResolverOption); final OptionInfo optionIMCCE = new OptionInfo("The IMCEE name resolver for solar system bodies"); optionIMCCE.setValue("IMCCE"); nameResolverOption.add(optionIMCCE); nameResolverParam.setOptions(nameResolverOption); final OptionInfo optionAll = new OptionInfo("Query all name resolvers"); optionAll.setValue("ALL"); nameResolverOption.add(optionAll); final String nameResolverFromModel = this.getModel().getParameterByName("nameResolver").getValue(); final String defaultNameResolver = (nameResolverFromModel != null && !nameResolverFromModel.isEmpty()) ? nameResolverFromModel : "CDS"; nameResolverParam.setDefaultValue(defaultNameResolver); parametersInfo.add(nameResolverParam); // Time frame for IMCCE final ParameterInfo time = new ParameterInfo( "epoch", false, "String", ParameterStyle.QUERY, "Time frame for IMCCE name resolver. See documentation from IMCCE"); final String timeFromModel = this.getModel().getParameterByName("epoch").getValue(); final String defaultTime = (timeFromModel != null && !timeFromModel.isEmpty()) ? timeFromModel : "now"; time.setDefaultValue(defaultTime); parametersInfo.add(time); // Set all parameters info.getRequest().setParameters(parametersInfo); // Response OK final ResponseInfo responseOK = new ResponseInfo(); List<RepresentationInfo> representationsInfo = new ArrayList<RepresentationInfo>(); RepresentationInfo representationInfo = new RepresentationInfo(MediaType.APPLICATION_JSON); final DocumentationInfo doc = new DocumentationInfo(); doc.setTitle("Name Resolver representation"); doc.setTextContent( "<pre>{\n" + "totalResults: 1,\n" + "type: \"FeatureCollection\",\n" + "features: [\n" + " geometry: {\n" + " coordinates: [10.6847083,41.26875],\n" + " type: \"Point\"\n" + " },\n" + "properties: {\n" + " crs: {\n" + " type: \"name\",\n" + " properties: {\n" + " name: \"EQUATORIAL.ICRS\"\n" + " }\n" + " },\n" + " credits: \"CDS\",\n" + " identifier: \"CDS0\"\n" + "}\n" + "}]}</pre>"); representationInfo.setDocumentation(doc); representationsInfo.add(representationInfo); responseOK.getRepresentations().add(representationInfo); responseOK.getStatuses().add(Status.SUCCESS_OK); // response bad request and internal error representationsInfo = new ArrayList<RepresentationInfo>(); representationInfo = new RepresentationInfo(MediaType.TEXT_HTML); representationInfo.setDocumentation("SITools2 status error page"); representationsInfo.add(representationInfo); final ResponseInfo responseError = new ResponseInfo(); responseError.getRepresentations().add(representationInfo); responseError.getStatuses().add(Status.SERVER_ERROR_INTERNAL); responseError.setDocumentation("Unexpected error"); final ResponseInfo responseBad = new ResponseInfo(); responseBad.getRepresentations().add(representationInfo); responseBad.getStatuses().add(Status.CLIENT_ERROR_BAD_REQUEST); responseBad.setDocumentation( Status.CLIENT_ERROR_BAD_REQUEST.getDescription() + "- coordinate system is unknown"); final ResponseInfo responseNotFound = new ResponseInfo(); responseNotFound.getRepresentations().add(representationInfo); responseNotFound.getStatuses().add(Status.CLIENT_ERROR_NOT_FOUND); responseNotFound.setDocumentation("object not found."); final ResponseInfo responseUnavailable = new ResponseInfo(); responseUnavailable.getRepresentations().add(representationInfo); responseUnavailable.getStatuses().add(Status.SERVER_ERROR_SERVICE_UNAVAILABLE); responseUnavailable.setDocumentation(Status.SERVER_ERROR_SERVICE_UNAVAILABLE.getDescription()); // Set responses final List<ResponseInfo> responseInfo = new ArrayList<ResponseInfo>(); responseInfo.add(responseOK); responseInfo.add(responseError); responseInfo.add(responseBad); responseInfo.add(responseUnavailable); responseInfo.add(responseNotFound); info.getResponses().addAll(responseInfo); }
/** * Helper Method creating common form of ParameterInfo * * @param name - ParameterInfo name * @param description - ParameterInfo description * @param defaultValue - ParameterInfo defaultValue. * @return ParameterInfo formatted : required=false, parameterStyle=Query, type="String". */ private static ParameterInfo createCommonParameter( String name, String description, String defaultValue) { ParameterInfo pi = new ParameterInfo(name, false, "String", ParameterStyle.QUERY, description); pi.setDefaultValue(defaultValue); return pi; }