/** * Returns the GeoJSON of the object name after calling all resolvers until an object is found or * all resolvers have been called. * * @return the GeoJSON of the object name */ private Representation callChainedResolver() { Map dataModel; final AbstractNameResolver cds = new CDSNameResolver(objectName, CDSNameResolver.NameResolverService.all); final AbstractNameResolver imcce = new IMCCESsoResolver(objectName, "now"); // final AbstractNameResolver corot = new CorotIdResolver(objectName); final AbstractNameResolver sitools2 = new ConstellationNameResolver(objectName); cds.setNext(sitools2); sitools2.setNext(imcce); // imcce.setNext(corot); final NameResolverResponse response = cds.getResponse(); if (!response.hasResult()) { throw new ResourceException( response.getError().getStatus(), response.getError().getMessage()); } final String credits = response.getCredits(); final List<AstroCoordinate> coordinates = response.getAstroCoordinates(); for (AstroCoordinate iter : coordinates) { iter.processTo(coordSystem); } dataModel = getDataModel(credits, coordinates, this.coordSystem.name()); Representation rep = new GeoJsonRepresentation(dataModel); final CacheBrowser.CacheDirectiveBrowser cacheDirective = (credits.equals("IMCCE")) ? CacheBrowser.CacheDirectiveBrowser.NO_CACHE : CacheBrowser.CacheDirectiveBrowser.FOREVER; final CacheBrowser cache = CacheBrowser.createCache(cacheDirective, rep); rep = cache.getRepresentation(); getResponse().setCacheDirectives(cache.getCacheDirectives()); return rep; }
/** * Returns the representation based on IMCCE response. * * @return the representation */ private Representation resolveIMCCE() { LOG.finest( String.format( "IMCCE name resolver is choosen with the following parameter %s", objectName)); final AbstractNameResolver imcce = new IMCCESsoResolver(objectName, epoch); final NameResolverResponse response = imcce.getResponse(); if (response.hasResult()) { LOG.log(Level.INFO, "IMCCE name resolver is selected for {0}.", objectName); getResponse().setStatus(Status.SUCCESS_OK); final List<AstroCoordinate> coordinates = response.getAstroCoordinates(); for (AstroCoordinate iter : coordinates) { iter.processTo(coordSystem); } final String credits = response.getCredits(); final Map dataModel = getDataModel(credits, coordinates, this.coordSystem.name()); Representation rep = new GeoJsonRepresentation(dataModel); final CacheBrowser cache = CacheBrowser.createCache(CacheBrowser.CacheDirectiveBrowser.NO_CACHE, rep); rep = cache.getRepresentation(); getResponse().setCacheDirectives(cache.getCacheDirectives()); return rep; } else { LOG.log(Level.WARNING, null, response.getError()); throw new ResourceException( response.getError().getStatus(), response.getError().getMessage()); } }
/** * Returns the data model for the JSON Representation of the name resolver. * * @param name credits * @param astroList results of the name resolver * @param referenceFrame ReferenceFrame * @return data model of the JSON representation */ private Map getDataModel( final String name, final List<AstroCoordinate> astroList, final String referenceFrame) { final FeaturesDataModel features = new FeaturesDataModel(); int index = 0; for (AstroCoordinate astroIter : astroList) { final FeatureDataModel feature = new FeatureDataModel(); feature.setIdentifier(name.concat(String.valueOf(index++))); feature.addProperty("credits", name); final Map<String, String> metadata = astroIter.getMatadata(); final Set<Entry<String, String>> entries = metadata.entrySet(); final Iterator<Entry<String, String>> iter = entries.iterator(); while (iter.hasNext()) { final Entry<String, String> entry = iter.next(); feature.addProperty(entry.getKey(), entry.getValue()); } feature.createCrs(CoordinateSystem.valueOf(referenceFrame).getCrs()); feature.createGeometry( String.format("[%s,%s]", astroIter.getRaAsDecimal(), astroIter.getDecAsDecimal()), "Point"); features.addFeature(feature); } return features.getFeatures(); }
/** * Returns the representation based on SITools2 db response. * * @return the representation */ private Representation resolveConstellation() { final AbstractNameResolver sitools2 = new ConstellationNameResolver(objectName); final NameResolverResponse response = sitools2.getResponse(); if (response.hasResult()) { LOG.log(Level.INFO, "Constellation name resolver is selected for {0}", objectName); getResponse().setStatus(Status.SUCCESS_OK); final List<AstroCoordinate> coordinates = response.getAstroCoordinates(); for (AstroCoordinate iter : coordinates) { iter.processTo(coordSystem); } final String credits = response.getCredits(); final Map dataModel = getDataModel(credits, coordinates, this.coordSystem.name()); Representation rep = new GeoJsonRepresentation(dataModel); final CacheBrowser cache = CacheBrowser.createCache(CacheBrowser.CacheDirectiveBrowser.FOREVER, rep); rep = cache.getRepresentation(); getResponse().setCacheDirectives(cache.getCacheDirectives()); return rep; } else { LOG.log(Level.WARNING, null, response.getError()); throw new ResourceException( response.getError().getStatus(), response.getError().getMessage()); } }