@Override public void attach(String sid) { if (this.sid != null) { throw new NuxeoException("Cannot attach a document that is already attached"); } this.sid = sid; }
public BlobHolderFactory getFactory() { try { return (BlobHolderFactory) adapterClass.newInstance(); } catch (ReflectiveOperationException e) { throw new NuxeoException(e); } }
public ThumbnailFactory getFactory() { try { return (ThumbnailFactory) factoryClass.newInstance(); } catch (ReflectiveOperationException e) { throw new NuxeoException(e); } }
@Override public void close() { if (tmpDir != null) { try { FileUtils.cleanDirectory(tmpDir); } catch (IOException e) { throw new NuxeoException(e); } } }
/** * CAUTION: if your cursor doesn't implement {@link Closeable}, we just set the field to null */ @Override public void close() { if (cursor instanceof Closeable) { try { ((Closeable) cursor).close(); } catch (IOException e) { throw new NuxeoException("Unable to close cursor", e); } } cursor = null; }
protected void setMemberValue(Object object, String name, Object value) throws PropertyException { if (object == null) { throw new NuxeoException("Trying to access a member of a null object: " + name); } if (!(object instanceof Blob)) { throw new NuxeoException("Not a Blob: " + object); } Blob blob = (Blob) object; setMemberValue(blob, name, value); }
@Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { if (XP.equals(extensionPoint)) { if (contribution instanceof BlobProviderDescriptor) { registerBlobProvider((BlobProviderDescriptor) contribution); } else { throw new NuxeoException("Invalid descriptor: " + contribution.getClass()); } } else { throw new NuxeoException("Invalid extension point: " + extensionPoint); } }
protected void setMap(Object object, Map<String, Object> value) throws PropertyException { if (object == null) { throw new NuxeoException("Trying to access a member of a null object"); } if (!(object instanceof Blob)) { throw new NuxeoException("Not a Blob: " + object); } Blob blob = (Blob) object; for (Entry<String, Object> entry : value.entrySet()) { String name = entry.getKey(); Object v = entry.getValue(); setMemberValue(blob, name, v); } }
protected void recompute() { Class<? extends PathSegmentService> klass; if (contribs.isEmpty()) { klass = PathSegmentServiceDefault.class; } else { klass = contribs.getLast(); } if (service == null || klass != service.getClass()) { try { service = klass.newInstance(); } catch (ReflectiveOperationException e) { throw new NuxeoException(e); } } // else keep old service instance }
@Override public void close() { fileCache.clear(); if (cachedir != null) { try { FileUtils.deleteDirectory(cachedir); } catch (IOException e) { throw new NuxeoException(e); } } }
/** * Gets the CoreSession, or fails if it's not available. * * @since 9.1 */ protected CoreSession getSession() { CoreSession session = getCoreSession(); if (session != null) { return session; } throw new NuxeoException("The DocumentModel is not associated to an open CoreSession: " + this); }
@Override public void initialize(String blobProviderId, Map<String, String> properties) throws IOException { super.initialize(blobProviderId, properties); root = properties.get(ROOT_PROP); if (StringUtils.isBlank(root)) { throw new NuxeoException( "Missing property '" + ROOT_PROP + "' for " + getClass().getSimpleName() + ": " + blobProviderId); } if ("/".equals(root)) { root = ""; } else if (!root.endsWith("/")) { root = root + "/"; } }
/** * Checks if the conversion to the given {@code mimeType} is supported by the {@code blob}. * * @param blob the managed blob * @param mimeType the destination mime type * @return {@code true} if this managed blob supports the conversion to the given mime type * @since 10.1 */ default boolean canConvert(ManagedBlob blob, String mimeType) { try { Map<String, URI> availableConversions = getAvailableConversions(blob, UsageHint.STREAM); return availableConversions.containsKey(mimeType); } catch (IOException e) { throw new NuxeoException(e); } }
@Override public void close() throws IOException { digest = messageDigest.digest(); try { byte[] bytes = cipher.doFinal(); out.write(bytes); bytes = null; // help GC } catch (GeneralSecurityException e) { throw new NuxeoException(e); } try { flush(); } finally { out.close(); } } }
@Override public void initialize(String blobProviderId, Map<String, String> properties) throws IOException { super.initialize(blobProviderId, properties); digestAlgorithm = getDigestAlgorithm(); String options = properties.get(BinaryManager.PROP_KEY); // TODO parse options from properties directly if (StringUtils.isBlank(options)) { throw new NuxeoException("Missing key for " + getClass().getSimpleName()); } initializeOptions(options); }
protected String getMD5Digest() { try (InputStream in = getBlob().getStream()) { return DigestUtils.md5Hex(in); } catch (IOException e) { throw new NuxeoException(e); } }
@Override public void internalSetValue(Serializable value) throws PropertyException { StringBuilder msg = newRemovedMessage(); if (fallback == null) { msg.append("Do nothing"); } else { msg.append("Set value to fallback property '").append(fallback.getXPath()).append("'"); } if (log.isTraceEnabled()) { log.error(msg, new NuxeoException("debug stack trace")); } else { log.error(msg); } if (fallback != null) { fallback.setValue(value); } }
@Override public Serializable internalGetValue() throws PropertyException { StringBuilder msg = newRemovedMessage(); if (fallback == null) { msg.append("Return null"); } else { msg.append("Return value from '").append(fallback.getXPath()).append("'"); } if (log.isTraceEnabled()) { log.error(msg, new NuxeoException()); } else { log.error(msg); } if (fallback == null) { return null; } return fallback.getValue(); }
public ThumbnailFactory getThumbnailFactory(DocumentModel doc, CoreSession session) { if (factoriesByDocType.containsKey(doc.getType())) { ThumbnailFactory factory = factoriesByDocType.get(doc.getType()); return factory; } for (Map.Entry<String, ThumbnailFactory> entry : factoriesByFacets.entrySet()) { if (doc.hasFacet(entry.getKey())) { return entry.getValue(); } } if (defaultFactory == null) { throw new NuxeoException("Please contribute a default thumbnail factory"); } return defaultFactory; } }
@Override public void mapProperties(CoreSession session, DocumentModel sourceDoc, DocumentModel targetDoc, String mapping) { Map<String, String> properties = getMapping(mapping); for (String keyProp : properties.keySet()) { // verify that mapping can be done Property sourceProperty = sourceDoc.getProperty(keyProp); Property targetProperty = targetDoc.getProperty(properties.get(keyProp)); Type sourceType = sourceProperty.getType(); Type targetType = targetProperty.getType(); if (!compatibleTypes(targetType, sourceType)) { throw new NuxeoException( String.format("Invalid mapping. Cannot map %s on type %s ", sourceType, targetType)); } targetDoc.setPropertyValue(targetProperty.getXPath(), sourceProperty.getValue()); } session.saveDocument(targetDoc); }