Package com.dotcms.publisher.business

Examples of com.dotcms.publisher.business.PublishAuditStatus


public class PublishAuditStatusMapper extends CommonRowMapper<PublishAuditStatus> {

  @Override
  public PublishAuditStatus mapObject(Map<String, Object> row) {
    PublishAuditStatus objToReturn = new PublishAuditStatus();
   
    objToReturn.setBundleId((String) row.get("bundle_id"));
    objToReturn.setStatusPojo(PublishAuditHistory
        .getObjectFromString(
            (String) row.get("status_pojo")));
   
    if(row.get("status") != null) {
      objToReturn.setStatus(PublishAuditStatus.getStatusObjectByCode(
          getIntegerFromObj(row.get("status"))));
    }
   
    objToReturn.setCreateDate((Date) row.get("create_date"));
    objToReturn.setStatusUpdated((Date) row.get("status_updated"));
   
    return objToReturn;
  }
View Full Code Here


    //At this points should not be here anymore
    foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertTrue( foundBundles == null || foundBundles.isEmpty() );

    //Get the audit records related to this bundle
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    //We will be able to retry failed and successfully bundles
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    //Get current status dates
    Date initialCreationDate = status.getCreateDate();
    Date initialUpdateDate = status.getStatusUpdated();

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //++++++++++++++++++++++++++++++RETRY++++++++++++++++++++++++++++++
    //Now we can try the retry
    req = ServletTestRunner.localRequest.get();
    baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/retry/u/admin@dotcms.com/p/admin";
    completeURL = baseURL + "?bundlesIds=" + UtilMethods.encodeURIComponent( bundleId );

    //Execute the call
    URL retryUrl = new URL( completeURL );
    response = IOUtils.toString( retryUrl.openStream(), "UTF-8" );//We can expect something like "Bundle id: <strong>1193e3eb-3ccd-496e-8995-29a9fcc48cbd</strong> added successfully to Publishing Queue."
    //Validations
    assertNotNull( response );
    assertTrue( response.contains( bundleId ) );
    assertTrue( response.contains( "added successfully to" ) );

    //And should be back to the queue job
    foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertNotNull( foundBundles );
    assertTrue( !foundBundles.isEmpty() );

    //Get current status dates
    status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );//Get the audit records related to this bundle
    Date latestCreationDate = status.getCreateDate();
    Date latestUpdateDate = status.getStatusUpdated();
    //Validations
    assertNotSame( initialCreationDate, latestCreationDate );
    assertNotSame( initialUpdateDate, latestUpdateDate );
    assertTrue( initialCreationDate.before( latestCreationDate ) );
    assertTrue( initialUpdateDate.before( latestUpdateDate ) );

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //++++++++++++++++++++SIMULATE AN END POINT++++++++++++++++++++++++
    /*
         And finally lets try to simulate a end point sending directly an already created bundle file to
         the api/bundlePublisher/publish service
     */

    //Create a receiving end point
    PublishingEndPoint receivingFromEndpoint = new PublishingEndPoint();
    receivingFromEndpoint.setServerName( new StringBuilder( "TestReceivingEndPoint" + String.valueOf( new Date().getTime() ) ) );
    receivingFromEndpoint.setAddress( req.getServerName() );
    receivingFromEndpoint.setPort( String.valueOf( req.getServerPort() ) );
    receivingFromEndpoint.setProtocol( "http" );
    receivingFromEndpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    receivingFromEndpoint.setEnabled( true );
    receivingFromEndpoint.setSending( true );//TODO: Shouldn't this be false as we are creating this end point to receive bundles from another server..?
    receivingFromEndpoint.setGroupId( environment.getId() );
    //Save the endpoint.
    publisherEndPointAPI.saveEndPoint( receivingFromEndpoint );

    //Find the bundle
    Bundle bundle = APILocator.getBundleAPI().getBundleById( bundleId );
    PublisherConfig basicConfig = new PublisherConfig();
    basicConfig.setId( bundleId );
    File bundleRoot = BundlerUtil.getBundleRoot( basicConfig );
    File bundleFile = new File( bundleRoot + File.separator + ".." + File.separator + bundle.getId() + ".tar.gz" );
   
    //lets wait one minute
    Thread.sleep( 60000 );
   
    assertTrue( bundleFile.exists() );

    //Rename the bundle file
    String newBundleId = UUID.randomUUID().toString();
    File newBundleFile = new File( bundleRoot + File.separator + ".." + File.separator + newBundleId + ".tar.gz" );
    Boolean success = bundleFile.renameTo( newBundleFile );
    assertTrue( success );
    assertTrue( newBundleFile.exists() );

    //Prepare the post request
    ClientConfig cc = new DefaultClientConfig();
    Client client = Client.create( cc );

    FormDataMultiPart form = new FormDataMultiPart();
    form.field( "AUTH_TOKEN", PublicEncryptionFactory.encryptString( (PublicEncryptionFactory.decryptString( receivingFromEndpoint.getAuthKey().toString() )) ) );
    form.field( "GROUP_ID", UtilMethods.isSet( receivingFromEndpoint.getGroupId() ) ? receivingFromEndpoint.getGroupId() : receivingFromEndpoint.getId() );
    form.field( "BUNDLE_NAME", bundle.getName() );
    form.field( "ENDPOINT_ID", receivingFromEndpoint.getId() );
    form.bodyPart( new FileDataBodyPart( "bundle", newBundleFile, MediaType.MULTIPART_FORM_DATA_TYPE ) );

    //Sending bundle to endpoint
    WebResource resource = client.resource( receivingFromEndpoint.toURL() + "/api/bundlePublisher/publish" );
    ClientResponse clientResponse = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, form );
    //Validations
    assertEquals( clientResponse.getClientResponseStatus().getStatusCode(), HttpStatus.SC_OK );

    //Get current status dates
    status = PublishAuditAPI.getInstance().getPublishAuditStatus( newBundleId );//Get the audit records related to this new bundle
    Date finalCreationDate = status.getCreateDate();
    Date finalUpdateDate = status.getStatusUpdated();
    //Validations
    assertNotSame( latestCreationDate.getTime(), finalCreationDate.getTime() );
    assertNotSame( latestUpdateDate.getTime(), finalUpdateDate.getTime() );
  }
View Full Code Here

    //assertTrue( foundBundles == null || foundBundles.isEmpty() );

    /*
     * Get the audit records related to this bundle
     */
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    /*
     * We will be able to retry failed and successfully bundles
     */
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    /*
     * deleting folder, pages and content, to create the receiving endpoint environment
     */
    APILocator.getContentletAPI().delete(contentlet, systemUser, false, true);
View Full Code Here


    /*
     * Get the audit records related to this bundle
     */
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    /*
     * We will be able to retry failed and successfully bundles
     */
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    /*
     * deleting folder, pages and contents, to create the receiving endpoint environment
     */
    APILocator.getContentletAPI().delete(contentlet1, systemUser, false, true);
View Full Code Here

      String bundlePath = ConfigUtils.getBundlePath()+File.separator+MY_TEMP;
      String fileName=fileDetail.getFileName();
      String bundleFolder = fileName.substring(0, fileName.indexOf(".tar.gz"));

            PublishAuditStatus status = PublishAuditAPI.getInstance().updateAuditTable( mySelf.getId(), mySelf.getId(), bundleFolder, true );

            if(bundleName.trim().length()>0) {
          // save bundle if it doesn't exists
                Bundle foundBundle = APILocator.getBundleAPI().getBundleById( bundleFolder );
                if ( foundBundle == null || foundBundle.getId() == null ) {
                    Bundle b = new Bundle();
                    b.setId(bundleFolder);
                    b.setName(bundleName);
                    b.setPublishDate(Calendar.getInstance().getTime());
                    b.setOwner(APILocator.getUserAPI().getSystemUser().getUserId());
                    APILocator.getBundleAPI().saveBundle(b);
          }
      }

      //Write file on FS
      FileUtil.writeToFile(bundle, bundlePath+fileName);

      //Start thread
      if(!status.getStatus().equals(Status.PUBLISHING_BUNDLE)) {
        new Thread(new PublishThread(fileName, groupId, endpointId, status)).start();
      }

      HibernateUtil.commitTransaction();
View Full Code Here

    @GET
    @Path("/get/{bundleId:.*}")
    @Produces(MediaType.TEXT_XML)
    public Response get(@PathParam("bundleId") String bundleId) {
        PublishAuditStatus status = null;

        try {
            status = auditAPI.getPublishAuditStatus(bundleId);

            if(status != null)
                return Response.ok((String) status.getStatusPojo().getSerialized()).build();
        } catch (DotPublisherException e) {
            Logger.warn(this, "error trying to get status for bundle "+bundleId,e);
        }

        return Response.status(404).build();
View Full Code Here

TOP

Related Classes of com.dotcms.publisher.business.PublishAuditStatus

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.