@Path("/") public Object doGetRepository(@PathParam("repo") String repositoryParam) throws DocumentNotFoundException { if (StringUtils.isNotBlank(repositoryParam)) { String repoName = repositoryParam.substring("repo/".length() + 1); try { ctx.setRepositoryName(repoName); } catch (IllegalArgumentException e) { throw new WebResourceNotFoundException(e.getMessage()); } } return newObject("repo"); }
@Path("group/{groupName:((?:(?!(/@)).)*)}") public Object doGetUserToGroup(@PathParam("groupName") String groupName) { NuxeoGroup group = um.getGroup(groupName); if (group == null) { throw new WebResourceNotFoundException("Group not found"); } return newObject("userToGroup", currentArtifact, group); }
@Override public ScriptFile getView(Module module, String name) { ScriptFile file = findView(module, name); if (file == null) { throw new WebResourceNotFoundException("Template " + name + " not found for object of type " + getName()); } return file; }
@Override public ResourceType getType(String typeName) { ResourceType type = getTypeRegistry().getType(typeName); if (type == null) { throw new WebResourceNotFoundException("Type not found: " + typeName); } return type; }
@Override public Resource newObject(String typeName, Object... args) { ResourceType type = module.getType(typeName); if (type == null) { throw new WebResourceNotFoundException("No Such Object Type: " + typeName); } return newObject(type, args); }
@Path("user/{username}") public Object doGetUserToGroup(@PathParam("username") String username) { UserManager um = Framework.getService(UserManager.class); NuxeoPrincipal principal = um.getPrincipal(username); if (principal == null) { throw new WebResourceNotFoundException("User not found"); } return newObject("userToGroup", principal, currentArtifact); }
protected OAuth2Client getClient(String clientId) { OAuth2Client client = Framework.getService(OAuth2ClientService.class).getClient(clientId); if (client == null) { throw new WebResourceNotFoundException("Invalid client: " + clientId); } return client; }
@Override public void render(String template, Object ctx, Writer writer) { ScriptFile script = getFile(template); if (script != null) { render(script, ctx, writer); } else { throw new WebResourceNotFoundException("Template not found: " + template); } }
@Override public Object runScript(String script, Map<String, Object> args) { ScriptFile sf = getFile(script); if (sf != null) { return runScript(sf, args); } else { throw new WebResourceNotFoundException("Script not found: " + script); } }
protected NuxeoOAuth2ServiceProvider getProvider(String providerId) { OAuth2ServiceProvider provider = Framework.getService(OAuth2ServiceProviderRegistry.class) .getProvider(providerId); if (provider == null || !(provider instanceof NuxeoOAuth2ServiceProvider)) { throw new WebResourceNotFoundException("Invalid provider: " + providerId); } return (NuxeoOAuth2ServiceProvider) provider; }
@Override protected void initialize(Object... args) { super.initialize(args); if (args.length < 1) { throw new IllegalArgumentException("Directory Object takes one parameter"); } String dirName = (String) args[0]; directory = Framework.getService(DirectoryService.class).getDirectory(dirName); if (directory == null) { throw new WebResourceNotFoundException("Directory " + dirName + " was not found"); } }
protected Blob getRenditionBlob() { RenditionService renditionService = Framework.getService(RenditionService.class); Rendition rendition = renditionService.getRendition(doc, renditionName); if (rendition == null) { throw new WebResourceNotFoundException(String.format("No rendition '%s' was found", renditionName)); } return rendition.getBlob(); }
private Directory getDirectoryFromEntry(final DirectoryEntry entry) { DirectoryService ds = Framework.getService(DirectoryService.class); Directory directory; try { directory = ds.getDirectory(entry.getDirectoryName()); } catch (DirectoryException e) { throw new WebResourceNotFoundException("directory not found"); } return directory; }
protected Blob convertWithMimeType(BlobHolder bh, String mimeType, UriInfo uriInfo) { Map<String, Serializable> parameters = computeConversionParameters(uriInfo); ConversionService conversionService = Framework.getService(ConversionService.class); BlobHolder blobHolder = conversionService.convertToMimeType(mimeType, bh, parameters); Blob conversionBlob = blobHolder.getBlob(); if (conversionBlob == null) { throw new WebResourceNotFoundException(String.format("No converted Blob for '%s' mime type", mimeType)); } return conversionBlob; }
protected Blob convertWithConverter(BlobHolder bh, String converter, UriInfo uriInfo) { ConversionService conversionService = Framework.getService(ConversionService.class); if (!conversionService.isConverterAvailable(converter).isAvailable()) { throw new IllegalParameterException(String.format("The '%s' converter is not available", converter)); } Map<String, Serializable> parameters = computeConversionParameters(uriInfo); BlobHolder blobHolder = conversionService.convert(converter, bh, parameters); Blob conversionBlob = blobHolder.getBlob(); if (conversionBlob == null) { throw new WebResourceNotFoundException(String.format("No converted Blob using '%s' converter", converter)); } return conversionBlob; }
@Override Object run(Session session) { DocumentModel entry = session.getEntry(entryId); if (entry == null) { throw new WebResourceNotFoundException("Entry not found"); } return newObject("directoryEntry", new DirectoryEntry(directory.getName(), entry), entryId); } });
@Override public AdapterType getAdapter(Resource ctx, String name) { AdapterType type = getTypeRegistry().getAdapter(ctx, name); if (type == null) { throw new WebResourceNotFoundException("Service " + name + " not found for object: " + ctx.getPath() + " of type " + ctx.getType().getName()); } return type; }
@Path("{label}") public DocumentObject getVersion(@PathParam("label") String label) { DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel doc = dobj.getDocument(); List<VersionModel> versions = dobj.getCoreSession().getVersionsForDocument(doc.getRef()); for (VersionModel v : versions) { if (label.equals(v.getLabel())) { return dobj.newDocument(dobj.getCoreSession().getDocumentWithVersion(doc.getRef(), v)); } } throw new WebResourceNotFoundException("No such version " + label + " for document" + getTarget().getPath()); }
protected void checkStatus(BulkStatus status) { if (status.getState() == State.UNKNOWN || !getContext().getPrincipal().isAdministrator() && !getContext().getPrincipal().getName().equals(status.getUsername())) { throw new WebResourceNotFoundException("Bulk command with id=" + status.getId() + " doesn't exist"); } } }
@Path("last") public DocumentObject getLastVersion() { DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel doc = dobj.getDocument(); DocumentModel v = dobj.getCoreSession().getLastDocumentVersion(doc.getRef()); if (v != null) { return dobj.newDocument(v); } throw new WebResourceNotFoundException( "No version found for " + ((DocumentObject) getTarget()).getDocument().getPath()); }