Search in sources :

Example 11 with Element

use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.

the class JukeboxPortletDataHandler method doExportData.

@Override
protected String doExportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences) throws Exception {
    Element rootElement = addExportDataRootElement(portletDataContext);
    if (portletDataContext.getBooleanParameter(NAMESPACE, "albums")) {
        ActionableDynamicQuery albumActionableDynamicQuery = new AlbumExportActionableDynamicQuery(portletDataContext);
        albumActionableDynamicQuery.performActions();
    }
    if (portletDataContext.getBooleanParameter(NAMESPACE, "artists")) {
        ActionableDynamicQuery artistActionableDynamicQuery = new ArtistExportActionableDynamicQuery(portletDataContext);
        artistActionableDynamicQuery.performActions();
    }
    return getExportDataRootElementString(rootElement);
}
Also used : Element(com.liferay.portal.kernel.xml.Element) AlbumExportActionableDynamicQuery(org.liferay.jukebox.service.persistence.AlbumExportActionableDynamicQuery) ArtistExportActionableDynamicQuery(org.liferay.jukebox.service.persistence.ArtistExportActionableDynamicQuery) AlbumExportActionableDynamicQuery(org.liferay.jukebox.service.persistence.AlbumExportActionableDynamicQuery) ArtistExportActionableDynamicQuery(org.liferay.jukebox.service.persistence.ArtistExportActionableDynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)

Example 12 with Element

use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.

the class JukeboxPortletDataHandler method doImportData.

@Override
protected PortletPreferences doImportData(PortletDataContext portletDataContext, String portletId, PortletPreferences portletPreferences, String data) throws Exception {
    if (portletDataContext.getBooleanParameter(NAMESPACE, "albums")) {
        Element albumsElement = portletDataContext.getImportDataGroupElement(Album.class);
        List<Element> albumElements = albumsElement.elements();
        for (Element albumElement : albumElements) {
            StagedModelDataHandlerUtil.importStagedModel(portletDataContext, albumElement);
        }
    }
    if (portletDataContext.getBooleanParameter(NAMESPACE, "artists")) {
        Element artistsElement = portletDataContext.getImportDataGroupElement(Artist.class);
        List<Element> artistElements = artistsElement.elements();
        for (Element artistElement : artistElements) {
            StagedModelDataHandlerUtil.importStagedModel(portletDataContext, artistElement);
        }
    }
    return null;
}
Also used : Element(com.liferay.portal.kernel.xml.Element)

Example 13 with Element

use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.

the class AlbumStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Album album) throws Exception {
    long userId = portletDataContext.getUserId(album.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(album);
    String artistPath = ExportImportPathUtil.getModelPath(portletDataContext, Artist.class.getName(), album.getArtistId());
    Artist artist = (Artist) portletDataContext.getZipEntryAsObject(artistPath);
    if (artist != null) {
        StagedModelDataHandlerUtil.importReferenceStagedModel(portletDataContext, album, Artist.class, album.getArtistId());
    }
    Map<Long, Long> artistIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Artist.class);
    long artistId = MapUtil.getLong(artistIds, album.getArtistId(), album.getArtistId());
    Album importedAlbum = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Album existingAlbum = AlbumLocalServiceUtil.fetchAlbumByUuidAndGroupId(album.getUuid(), portletDataContext.getScopeGroupId());
        if (existingAlbum == null) {
            serviceContext.setUuid(album.getUuid());
            importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
        } else {
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, existingAlbum.getAlbumId(), artistId, album.getName(), album.getYear(), null, serviceContext);
        }
    } else {
        importedAlbum = AlbumLocalServiceUtil.addAlbum(userId, artistId, album.getName(), album.getYear(), null, serviceContext);
    }
    Element albumElement = portletDataContext.getImportDataStagedModelElement(album);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(albumElement, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");
        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);
        InputStream inputStream = null;
        try {
            String binPath = attachmentElement.attributeValue("bin-path");
            if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {
                try {
                    inputStream = _getContentStream(fileEntry);
                } catch (NoSuchFileException nsfe) {
                }
            } else {
                inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
            }
            if (inputStream == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
                }
                continue;
            }
            importedAlbum = AlbumLocalServiceUtil.updateAlbum(userId, importedAlbum.getAlbumId(), importedAlbum.getArtistId(), importedAlbum.getName(), importedAlbum.getYear(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(album, importedAlbum);
}
Also used : Artist(org.liferay.jukebox.model.Artist) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) NoSuchFileException(com.liferay.portlet.documentlibrary.NoSuchFileException) Album(org.liferay.jukebox.model.Album) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry) Map(java.util.Map)

Example 14 with Element

use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method doExportStagedModel.

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {
    Element artistElement = portletDataContext.getExportDataElement(artist);
    if (artist.hasCustomImage()) {
        FileEntry fileEntry = artist.getCustomImage();
        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, artist, Artist.class, fileEntry, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    }
    portletDataContext.addClassedModel(artistElement, ExportImportPathUtil.getModelPath(artist), artist);
}
Also used : Element(com.liferay.portal.kernel.xml.Element) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 15 with Element

use of com.liferay.portal.kernel.xml.Element in project liferay-ide by liferay.

the class ArtistStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Artist artist) throws Exception {
    long userId = portletDataContext.getUserId(artist.getUserUuid());
    ServiceContext serviceContext = portletDataContext.createServiceContext(artist);
    Artist importedArtist = null;
    if (portletDataContext.isDataStrategyMirror()) {
        Artist existingArtist = ArtistLocalServiceUtil.fetchArtistByUuidAndGroupId(artist.getUuid(), portletDataContext.getScopeGroupId());
        if (existingArtist == null) {
            serviceContext.setUuid(artist.getUuid());
            importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
        } else {
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, existingArtist.getArtistId(), artist.getName(), artist.getBio(), null, serviceContext);
        }
    } else {
        importedArtist = ArtistLocalServiceUtil.addArtist(userId, artist.getName(), artist.getBio(), null, serviceContext);
    }
    Element artistElement = portletDataContext.getImportDataStagedModelElement(artist);
    List<Element> attachmentElements = portletDataContext.getReferenceDataElements(artistElement, FileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);
    for (Element attachmentElement : attachmentElements) {
        String path = attachmentElement.attributeValue("path");
        FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);
        InputStream inputStream = null;
        try {
            String binPath = attachmentElement.attributeValue("bin-path");
            if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {
                try {
                    inputStream = _getContentStream(fileEntry);
                } catch (NoSuchFileException nsfe) {
                }
            } else {
                inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
            }
            if (inputStream == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId());
                }
                continue;
            }
            importedArtist = ArtistLocalServiceUtil.updateArtist(userId, importedArtist.getArtistId(), importedArtist.getName(), importedArtist.getBio(), inputStream, serviceContext);
        } finally {
            StreamUtil.cleanUp(inputStream);
        }
    }
    portletDataContext.importClassedModel(artist, importedArtist);
}
Also used : Artist(org.liferay.jukebox.model.Artist) ServiceContext(com.liferay.portal.service.ServiceContext) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) InputStream(java.io.InputStream) Element(com.liferay.portal.kernel.xml.Element) NoSuchFileException(com.liferay.portlet.documentlibrary.NoSuchFileException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Aggregations

Element (com.liferay.portal.kernel.xml.Element)22 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)5 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)5 ServiceContext (com.liferay.portal.service.ServiceContext)4 InputStream (java.io.InputStream)4 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)3 SystemException (com.liferay.portal.kernel.exception.SystemException)3 UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)3 NoSuchTagException (com.liferay.portlet.asset.NoSuchTagException)3 ImportFilesException (com.liferay.portlet.wiki.ImportFilesException)3 Artist (org.liferay.jukebox.model.Artist)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 KBFolder (com.liferay.knowledgebase.model.KBFolder)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 ProgressTracker (com.liferay.portal.kernel.util.ProgressTracker)2 Document (com.liferay.portal.kernel.xml.Document)2 DocumentException (com.liferay.portal.kernel.xml.DocumentException)2 NoSuchFileException (com.liferay.portlet.documentlibrary.NoSuchFileException)2 NoSuchPageException (com.liferay.portlet.wiki.NoSuchPageException)2 IOException (java.io.IOException)2