private SimpleDocument createFrenchSimpleAttachment() { String language = "fr"; String fileName = "test.odp"; String title = "Mon document de test"; String description = "Ceci est un document de test"; String creatorId = "10"; Date creationDate = RandomGenerator.getRandomCalendar().getTime(); SimpleAttachment file = new SimpleAttachment( fileName, language, title, description, "Ceci est un test".getBytes(Charsets.UTF_8).length, MimeTypes.MIME_TYPE_OO_PRESENTATION, creatorId, creationDate, null); SimpleDocumentPK pk = new SimpleDocumentPK(null, instanceId); pk.setOldSilverpeasId(5); SimpleDocument attachment = new HistorisedDocument(); attachment.setPK(pk); attachment.setFile(file); attachment.setForeignId("12"); return AttachmentServiceFactory.getAttachmentService() .createAttachment( attachment, new ByteArrayInputStream("Ceci est un test".getBytes(Charsets.UTF_8))); }
SimpleDocument fillDocument(Node node, String lang) throws RepositoryException { SimpleDocumentPK pk = new SimpleDocumentPK( node.getIdentifier(), getStringProperty(node, SLV_PROPERTY_INSTANCEID)); long oldSilverpeasId = getLongProperty(node, SLV_PROPERTY_OLD_ID); pk.setOldSilverpeasId(oldSilverpeasId); String language = lang; if (language == null) { language = I18NHelper.defaultLanguage; } SimpleAttachment file = getAttachment(node, language); if (file == null) { Iterator<String> iter = I18NHelper.getLanguages(); while (iter.hasNext() && file == null) { file = getAttachment(node, iter.next()); } } SimpleDocument doc = new SimpleDocument( pk, getStringProperty(node, SLV_PROPERTY_FOREIGN_KEY), getIntProperty(node, SLV_PROPERTY_ORDER), getBooleanProperty(node, SLV_PROPERTY_VERSIONED), getStringProperty(node, SLV_PROPERTY_OWNER), getDateProperty(node, SLV_PROPERTY_RESERVATION_DATE), getDateProperty(node, SLV_PROPERTY_ALERT_DATE), getDateProperty(node, SLV_PROPERTY_EXPIRY_DATE), getStringProperty(node, SLV_PROPERTY_COMMENT), file); doc.setRepositoryPath(node.getPath()); doc.setCloneId(getStringProperty(node, SLV_PROPERTY_CLONE)); doc.setMajorVersion(getIntProperty(node, SLV_PROPERTY_MAJOR)); doc.setMinorVersion(getIntProperty(node, SLV_PROPERTY_MINOR)); doc.setStatus(getStringProperty(node, SLV_PROPERTY_STATUS)); doc.setDocumentType(DocumentType.fromFolderName(node.getParent().getName())); String nodeName = node.getName(); if ("jcr:frozenNode".equals(nodeName)) { nodeName = doc.computeNodeName(); doc.setNodeName(nodeName); if (!node.getSession().nodeExists(doc.getFullJcrPath())) { nodeName = SimpleDocument.VERSION_PREFIX + doc.getOldSilverpeasId(); } } doc.setNodeName(nodeName); doc.setPublicDocument(!doc.isVersioned() || doc.getMinorVersion() == 0); // Forbidden download for roles String forbiddenDownloadForRoles = getStringProperty(node, SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES); if (StringUtil.isDefined(forbiddenDownloadForRoles)) { doc.addRolesForWhichDownloadIsForbidden(SilverpeasRole.listFrom(forbiddenDownloadForRoles)); } return doc; }
@Test public void testIsNotReadable() { createFrenchSimpleAttachment(); SimpleDocumentPK pk = new SimpleDocumentPK(null, instanceId); pk.setOldSilverpeasId(10); SimpleDocument attachment = new HistorisedDocument(); attachment.setPK(pk); attachment.setForeignId("15"); ShareableAttachment resource = new ShareableAttachment( "965e985d-c711-47b3-a467-62779505965e985d-c711-47b3-a467-62779505", attachment); SimpleFileAccessControl instance = new SimpleFileAccessControl(); boolean expResult = false; boolean result = instance.isReadable(resource); assertThat(result, is(expResult)); }