ReportContentLocation implements ContentLocation { public ContentItem createItem( final String name ) throws ContentCreationException { IUnifiedRepository repo = PentahoSystem.get( IUnifiedRepository.class ); final String extension = IOUtils.getInstance().getFileExtension( name ); final String mimeType = MimeHelper.getMimeTypeFromExtension( extension ); RepositoryFileOutputStream rfos = null; String path = this.location.getPath() + "/" + name; if ( repo.getFile( path ) == null ) { if ( isHiddenExtension( extension ) ) { rfos = new RepositoryFileOutputStream( path, true ); } else { rfos = new RepositoryFileOutputStream( path, false ); } try { rfos.close(); } catch ( IOException e ) { throw new ContentCreationException( e.getMessage(), e ); } } Map<String, Serializable> meta = repo.getFileMetadata( repo.getFile( path ).getId() ); meta.put( RESERVEDMAPKEY_LINEAGE_ID, UUID.randomUUID().toString() ); repo.setFileMetadata( repo.getFile( path ).getId(), meta ); return new ReportContentItem( repo.getFile( path ), this, mimeType ); } ReportContentLocation( final RepositoryFile location, final ReportContentRepository repository ); ContentEntity[] listContents(); ContentEntity getEntry( final String name ); ContentItem createItem( final String name ); ContentLocation createLocation( final String string ); boolean exists( final String name ); String getName(); Object getContentId(); Object getAttribute( final String domain, final String key ); boolean setAttribute( final String domain, final String key, final Object object ); ContentLocation getParent(); Repository getRepository(); boolean delete(); boolean isHiddenExtension( String extension ); static final String RESERVEDMAPKEY_LINEAGE_ID; }
@Test public void testCreateItem() throws Exception { final HashMap<String, Serializable> metadata = new HashMap<>(); when( repository.getFile( anyString() ) ).thenReturn( repositoryFile ); when( repository.getFileMetadata( any() ) ).thenReturn( metadata ); when( repositoryFile.getPath() ).thenReturn( "/testPath" ); reportContentLocation.createItem( "testName" ); Assert.assertTrue( repository.getFileMetadata( repositoryFile.getId() ).containsKey( ReportContentLocation.RESERVEDMAPKEY_LINEAGE_ID ) ); }