Search in sources :

Example 1 with QNameAlreadyExistsException

use of org.eclipse.winery.common.interfaces.QNameAlreadyExistsException in project winery by eclipse.

the class WineryRepositoryClient method createComponent.

@Override
public void createComponent(QName qname, Class<? extends DefinitionsChildId> idClass) throws QNameAlreadyExistsException {
    WebResource resource = this.primaryWebResource.path(Util.getRootPathFragment(idClass));
    MultivaluedMap<String, String> map = new MultivaluedMapImpl();
    map.putSingle("namespace", qname.getNamespaceURI());
    map.putSingle("name", qname.getLocalPart());
    ClientResponse response = resource.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, map);
    if (response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
        // TODO: pass ClientResponse.Status somehow
        // TODO: more fine grained checking for error message. Not all failures are that the QName already exists
        LOGGER.debug(String.format("Error %d when creating id %s from URI %s", response.getStatus(), qname.toString(), this.primaryWebResource.getURI().toString()));
        throw new QNameAlreadyExistsException();
    }
// no further return is made
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) QNameAlreadyExistsException(org.eclipse.winery.common.interfaces.QNameAlreadyExistsException) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Example 2 with QNameAlreadyExistsException

use of org.eclipse.winery.common.interfaces.QNameAlreadyExistsException in project winery by eclipse.

the class WineryRepositoryClient method createArtifactTemplate.

/**
 * Does NOT check for global QName uniqueness, only in the scope of all
 * artifact templates
 */
@Override
public void createArtifactTemplate(QName qname, QName artifactType) throws QNameAlreadyExistsException {
    WebResource artifactTemplates = this.primaryWebResource.path("artifacttemplates");
    MultivaluedMap<String, String> map = new MultivaluedMapImpl();
    map.putSingle("namespace", qname.getNamespaceURI());
    map.putSingle("name", qname.getLocalPart());
    map.putSingle("type", artifactType.toString());
    ClientResponse response = artifactTemplates.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.TEXT_PLAIN).post(ClientResponse.class, map);
    if (response.getClientResponseStatus() != ClientResponse.Status.CREATED) {
        // TODO: pass ClientResponse.Status somehow
        // TODO: more fine grained checking for error message. Not all
        // failures are that the QName already exists
        LOGGER.debug(String.format("Error %d when creating id %s from URI %s", response.getStatus(), qname.toString(), this.primaryWebResource.getURI().toString()));
        throw new QNameAlreadyExistsException();
    }
// no further return is made
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) QNameAlreadyExistsException(org.eclipse.winery.common.interfaces.QNameAlreadyExistsException) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 QNameAlreadyExistsException (org.eclipse.winery.common.interfaces.QNameAlreadyExistsException)2