Package com.dotcms.publisher.pusher

Examples of com.dotcms.publisher.pusher.PushPublisherConfig


        try {
            //Read the bundle to see what kind of configuration we need to apply
            String finalBundlePath = ConfigUtils.getBundlePath() + File.separator + bundleFolder;
            File xml = new File( finalBundlePath + File.separator + "bundle.xml" );
            PushPublisherConfig readConfig = (PushPublisherConfig) BundlerUtil.xmlToObject( xml );

            //Get the identifiers on this bundle
            assetsDetails = new HashMap<String, String>();
            List<PublishQueueElement> bundlerAssets = readConfig.getAssets();

            if ( bundlerAssets != null && !bundlerAssets.isEmpty() ) {
                for ( PublishQueueElement asset : bundlerAssets ) {
                    assetsDetails.put( asset.getAsset(), asset.getType() );
                }
View Full Code Here


            try {

                //Read the bundle to see what kind of configuration we need to apply
                String bundlePath = ConfigUtils.getBundlePath() + File.separator + basicConfig.getId();
                File xml = new File( bundlePath + File.separator + "bundle.xml" );
                PushPublisherConfig config = (PushPublisherConfig) BundlerUtil.xmlToObject( xml );

                //We can not retry Received Bundles, just bundles that we are trying to send
                Boolean sending = sendingBundle( request, config, bundleId );
                if ( !sending ) {
                    appendMessage( responseMessage, "publisher_retry.error.cannot.retry.received", bundleId, true );
                    continue;
                }

                if ( status.getStatus().equals( Status.SUCCESS ) ) {

                    //Get the bundle
                    Bundle bundle = APILocator.getBundleAPI().getBundleById( bundleId );
                    if ( bundle == null ) {
                        Logger.error( this.getClass(), "No Bundle with id: " + bundleId + " found." );
                        appendMessage( responseMessage, "publisher_retry.error.not.found", bundleId, true );
                        continue;
                    }
                    bundle.setForcePush( true );
                    APILocator.getBundleAPI().updateBundle( bundle );
                }

                //Clean the number of tries, we want to try it again
                auditHistory.setNumTries( 0 );
                publishAuditAPI.updatePublishAuditStatus( config.getId(), status.getStatus(), auditHistory, true );

                //Get the identifiers on this bundle
                HashSet<String> identifiers = new HashSet<String>();
                List<PublishQueueElement> assets = config.getAssets();
                if ( config.getLuceneQueries() != null && !config.getLuceneQueries().isEmpty() ) {
                    identifiers.addAll( PublisherUtil.getContentIds( config.getLuceneQueries() ) );
                }
                if ( assets != null && !assets.isEmpty() ) {
                    for ( PublishQueueElement asset : assets ) {
                        identifiers.add( asset.getAsset() );
                    }
                }

                //Cleaning previous bundle folder and tar file to avoid sending modified data
                FileUtils.cleanDirectory(new File(bundlePath));
                bundleFile.delete();
               
                //Now depending of the operation lets add it to the queue job
                if ( config.getOperation().equals( PushPublisherConfig.Operation.PUBLISH ) ) {
                    publisherAPI.addContentsToPublish( new ArrayList<String>( identifiers ), bundleId, new Date(), getUser() );
                } else {
                    publisherAPI.addContentsToUnpublish( new ArrayList<String>( identifiers ), bundleId, new Date(), getUser() );
                }
View Full Code Here

     * @throws IOException If fails compressing the all the Bundle contents into the final Bundle file
     */
    @SuppressWarnings ("unchecked")
    private Map<String, Object> generateBundle ( String bundleId, PushPublisherConfig.Operation operation ) throws DotPublisherException, DotDataException, DotPublishingException, IllegalAccessException, InstantiationException, DotBundleException, IOException {

        PushPublisherConfig pconf = new PushPublisherConfig();
        PublisherAPI pubAPI = PublisherAPI.getInstance();

        List<PublishQueueElement> tempBundleContents = pubAPI.getQueueElementsByBundleId( bundleId );
        List<PublishQueueElement> assetsToPublish = new ArrayList<PublishQueueElement>(); // all assets but contentlets

        for ( PublishQueueElement c : tempBundleContents ) {
            if ( !c.getType().equals( "contentlet" ) ) {
                assetsToPublish.add( c );
            }
        }

        pconf.setDownloading( true );
        pconf.setOperation(operation);

        // all types of assets in the queue but contentlets are passed here, which are passed through lucene queries
        pconf.setAssets( assetsToPublish );
        //Queries creation
        pconf.setLuceneQueries( PublisherUtil.prepareQueries( tempBundleContents ) );
        pconf.setId( bundleId );
        pconf.setUser( APILocator.getUserAPI().getSystemUser() );

        //BUNDLERS

        List<Class<IBundler>> bundlers = new ArrayList<Class<IBundler>>();
        List<IBundler> confBundlers = new ArrayList<IBundler>();

        Publisher publisher = new PushPublisher();
        publisher.init( pconf );
        //Add the bundles for this publisher
        for ( Class clazz : publisher.getBundlers() ) {
            if ( !bundlers.contains( clazz ) ) {
                bundlers.add( clazz );
            }
        }

        //Create a new bundle id for this generated bundle
        String newBundleId = UUID.randomUUID().toString();
        pconf.setId( newBundleId );
        File bundleRoot = BundlerUtil.getBundleRoot( pconf );

        // Run bundlers
        BundlerUtil.writeBundleXML( pconf );
        for ( Class<IBundler> c : bundlers ) {

            IBundler bundler = c.newInstance();
            confBundlers.add( bundler );
            bundler.setConfig( pconf );
            BundlerStatus bundlerStatus = new BundlerStatus( bundler.getClass().getName() );
            //Generate the bundler
            bundler.generate( bundleRoot, bundlerStatus );
        }

        pconf.setBundlers( confBundlers );

        //Compressing bundle
        ArrayList<File> list = new ArrayList<File>();
        list.add( bundleRoot );
        File bundle = new File( bundleRoot + File.separator + ".." + File.separator + pconf.getId() + ".tar.gz" );

        Map<String, Object> bundleData = new HashMap<String, Object>();
        bundleData.put( "id", newBundleId );
        bundleData.put( "file", PushUtils.compressFiles( list, bundle, bundleRoot.getAbsolutePath() ) );
        return bundleData;
View Full Code Here

              assets.put( c.getAsset(), c.getType());
              assetsToPublish.add(c);
            }
            historyPojo.setAssets(assets);

            PushPublisherConfig pconf = new PushPublisherConfig();
            pconf.setAssets(assetsToPublish);

            //Status
            status =  new PublishAuditStatus(tempBundleId);
            status.setStatusPojo(historyPojo);

            //Insert in Audit table
            pubAuditAPI.insertPublishAuditStatus(status);

            //Queries creation
            pconf.setLuceneQueries(PublisherUtil.prepareQueries(tempBundleContents));
            pconf.setId(tempBundleId);
            pconf.setUser(APILocator.getUserAPI().getSystemUser());
            pconf.setStartDate(new Date());
            pconf.runNow();

            pconf.setPublishers(clazz);
//            pconf.setEndpoints(endpoints);

                        if ( Integer.parseInt( bundle.get( "operation" ).toString() ) == PublisherAPI.ADD_OR_UPDATE_ELEMENT ) {
                            pconf.setOperation( PushPublisherConfig.Operation.PUBLISH );
                        } else {
                            pconf.setOperation( PushPublisherConfig.Operation.UNPUBLISH );
                        }

                        try {
                            APILocator.getPublisherAPI().publish( pconf );
                        } catch ( DotPublishingException e ) {
                            /*
                            If we are getting errors creating the bundle we should stop trying to publish it, this is not just a connection error,
                            there is something wrong with a bundler or creating the bundle.
                             */
                            Logger.error( PublisherQueueJob.class, "Unable to publish Bundle: " + e.getMessage(), e );
                            pubAuditAPI.updatePublishAuditStatus( pconf.getId(), PublishAuditStatus.Status.FAILED_TO_BUNDLE, historyPojo );
                            pubAPI.deleteElementsFromPublishQueueTable( pconf.getId() );
                        }
                    }

        }

View Full Code Here

TOP

Related Classes of com.dotcms.publisher.pusher.PushPublisherConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.