Search in sources :

Example 1 with License

use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.

the class ReferencedSiteRootResource method getLicenseInfo.

@GET
@Path(value = ReferencedSiteRootResource.LICENSE_PATH + "/{name}")
public Response getLicenseInfo(@PathParam(value = "site") String siteId, @Context HttpHeaders headers, @Context UriInfo uriInfo, @PathParam(value = "name") String name) {
    Site site = getSite(siteId);
    MediaType acceptedMediaType = getAcceptableMediaType(headers, MediaType.APPLICATION_JSON_TYPE);
    if (name == null || name.isEmpty()) {
    // return all
    } else if (name.startsWith(LICENSE_NAME)) {
        try {
            String numberString = name.substring(LICENSE_NAME.length());
            if (numberString.isEmpty()) {
                numberString = "0";
            }
            // license0 is the first one
            int count = -1;
            if (site.getConfiguration().getLicenses() != null) {
                for (License license : site.getConfiguration().getLicenses()) {
                    if (license.getUrl() == null) {
                        count++;
                    }
                    if (Integer.toString(count).equals(numberString)) {
                        ResponseBuilder rb = Response.ok(license2Representation(uriInfo.getAbsolutePath().toString(), license));
                        rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType + "; charset=utf-8");
                        // addCORSOrigin(servletContext, rb, headers);
                        return rb.build();
                    }
                }
            }
        } catch (NumberFormatException e) {
            return Response.status(Status.NOT_FOUND).entity("No License found.\n").header(HttpHeaders.ACCEPT, acceptedMediaType).build();
        }
    }
    return Response.status(Response.Status.NOT_FOUND).build();
}
Also used : ManagedSite(org.apache.stanbol.entityhub.servicesapi.site.ManagedSite) Site(org.apache.stanbol.entityhub.servicesapi.site.Site) License(org.apache.stanbol.entityhub.servicesapi.site.License) MediaType(javax.ws.rs.core.MediaType) MediaTypeUtil.getAcceptableMediaType(org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) EntityhubLDPath(org.apache.stanbol.entityhub.ldpath.EntityhubLDPath) GET(javax.ws.rs.GET)

Example 2 with License

use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.

the class ReferencedSiteRootResource method site2Representation.

/*
     * Referenced Site Metadata
     */
/**
 * Transforms a site to a Representation that can be serialised
 * @param context
 * @return
 */
private Representation site2Representation(Site site, String id) {
    RdfValueFactory valueFactory = RdfValueFactory.getInstance();
    RdfRepresentation rep = valueFactory.createRepresentation(id);
    String namespace = NamespaceEnum.entityhub.getNamespace();
    rep.add(namespace + "localMode", site.supportsLocalMode());
    rep.add(namespace + "supportsSearch", site.supportsSearch());
    SiteConfiguration config = site.getConfiguration();
    rep.add("http://www.w3.org/2000/01/rdf-schema#label", config.getName());
    rep.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#type", valueFactory.createReference(namespace + "ReferencedSite"));
    if (config.getDescription() != null) {
        rep.add("http://www.w3.org/2000/01/rdf-schema#description", config.getDescription());
    }
    if (config.getAttribution() != null) {
        rep.add("http://creativecommons.org/ns#attributionName", config.getAttribution());
    }
    if (config.getAttributionUrl() != null) {
        rep.add("http://creativecommons.org/ns#attributionURL", config.getAttributionUrl());
    }
    // add the licenses
    if (config.getLicenses() != null) {
        int count = 0;
        for (License license : config.getLicenses()) {
            String licenseUrl;
            if (license.getUrl() != null) {
                licenseUrl = license.getUrl();
            } else {
                licenseUrl = id + (!id.endsWith("/") ? "/" : "") + LICENSE_PATH + '/' + LICENSE_NAME + (count > 0 ? count : "");
                count++;
            }
            // if defined add the name to dc:license
            if (license.getName() != null) {
                rep.add("http://purl.org/dc/terms/license", licenseUrl);
            }
            // link to the license via cc:license
            rep.add("http://creativecommons.org/ns#license", licenseUrl);
        }
    }
    if (config.getEntityPrefixes() != null) {
        for (String prefix : config.getEntityPrefixes()) {
            rep.add(namespace + "entityPrefix", prefix);
        }
    } else {
        // all entities are allowed/processed
        rep.add(namespace + "entityPrefix", "*");
    }
    if (config instanceof ReferencedSiteConfiguration) {
        ReferencedSiteConfiguration refConfig = (ReferencedSiteConfiguration) config;
        if (refConfig.getCacheStrategy() != null) {
            rep.add(namespace + "cacheStrategy", valueFactory.createReference(namespace + "cacheStrategy-" + refConfig.getCacheStrategy().name()));
        }
        // add the accessUri and queryUri
        if (refConfig.getAccessUri() != null) {
            rep.add(namespace + "accessUri", valueFactory.createReference(refConfig.getAccessUri()));
        }
        if (refConfig.getQueryUri() != null) {
            rep.add(namespace + "queryUri", valueFactory.createReference(refConfig.getQueryUri()));
        }
    }
    return rep;
}
Also used : ReferencedSiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration) RdfRepresentation(org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation) License(org.apache.stanbol.entityhub.servicesapi.site.License) SiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration) ReferencedSiteConfiguration(org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration) RdfValueFactory(org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)

Example 3 with License

use of org.apache.stanbol.entityhub.servicesapi.site.License in project stanbol by apache.

the class SiteConfigurationImpl method getLicenses.

@Override
public final License[] getLicenses() {
    // get Licenses based on related keys
    int elements = 0;
    String[] names = getLicenseName();
    if (names == null) {
        names = new String[] {};
    } else {
        elements = Math.max(elements, names.length);
    }
    String[] texts = getLicenseText();
    if (texts == null) {
        texts = new String[] {};
    } else {
        elements = Math.max(elements, texts.length);
    }
    String[] urls = getLicenseUrl();
    if (urls == null) {
        urls = new String[] {};
    } else {
        elements = Math.max(elements, urls.length);
    }
    Collection<License> licenseList = new ArrayList<License>();
    for (int i = 0; i < elements; i++) {
        try {
            licenseList.add(new License(names.length > i ? names[i] : null, urls.length > i ? urls[i] : null, texts.length > i ? texts[i] : null));
        } catch (IllegalArgumentException e) {
        // ignore if name, text and url == null and/or empty
        }
    }
    return licenseList.isEmpty() ? new License[] {} : licenseList.toArray(new License[licenseList.size()]);
}
Also used : License(org.apache.stanbol.entityhub.servicesapi.site.License) ArrayList(java.util.ArrayList)

Aggregations

License (org.apache.stanbol.entityhub.servicesapi.site.License)3 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 MediaType (javax.ws.rs.core.MediaType)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)1 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)1 RdfRepresentation (org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation)1 RdfValueFactory (org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory)1 ManagedSite (org.apache.stanbol.entityhub.servicesapi.site.ManagedSite)1 ReferencedSiteConfiguration (org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteConfiguration)1 Site (org.apache.stanbol.entityhub.servicesapi.site.Site)1 SiteConfiguration (org.apache.stanbol.entityhub.servicesapi.site.SiteConfiguration)1