Search in sources :

Example 11 with PublishJob

use of org.storymaker.app.model.PublishJob in project storymaker by StoryMaker.

the class PublishController method startRender.

public void startRender(int publishJobId) {
    PublishJob publishJob = getPublishJob(publishJobId);
    PublisherBase publisher = getPublisher(publishJob);
    // TODO this needs to loop a few times until publisher start returns false or something to tell us that the publish job is totally finished
    if (publisher != null) {
        publisher.startRender();
    }
}
Also used : PublishJob(org.storymaker.app.model.PublishJob)

Example 12 with PublishJob

use of org.storymaker.app.model.PublishJob in project storymaker by StoryMaker.

the class PublishFragment method startPublish.

// FIXME don't pass intent, this needs to be usable by storypaths with publishprofiles and hence which skip the accountlist activity
private void startPublish() {
    showUploadSpinner(true);
    mUploading = true;
    mPlaying = false;
    //                    if (mFileLastExport != null && mFileLastExport.exists()) { // FIXME replace this with a check to make sure render is suitable
    //                    if (mMatchingRenderJob != null) {
    //                        // FIXME i think we need to add that render job to this publishJob here
    //                        PublishJob publishJob = PublishController.getMatchingPublishJob(getActivity().getApplicationContext(), mActivity.mMPM.mProject, mSiteKeys, publishJob.getMetadataString());
    //                        Job newJob = JobTable.cloneJob(getActivity().getApplicationContext(), mMatchingRenderJob);
    //                        newJob.setPublishJobId(publishJob.getId());
    //                        newJob.save();
    //                        mMatchingRenderJob = newJob;
    //                        startUpload(mActivity.mMPM.mProject, mSiteKeys, useTor, publishToStoryMaker);
    //                    } else {
    //                        startRender(mActivity.mMPM.mProject, mSiteKeys, useTor, publishToStoryMaker);
    //                    }
    // FIXME this is "a bit" of a hack, we should write an automated way of converting Bundle to HashMap ... or maybe we should be passing a bundle?
    HashMap<String, String> metadata = new HashMap<String, String>();
    metadata.put(SiteController.VALUE_KEY_PUBLISH_TO_STORYMAKER, publishToStoryMaker ? "true" : "false");
    metadata.put(SiteController.VALUE_KEY_USE_TOR, useTor ? "true" : "false");
    metadata.put(SiteController.VALUE_KEY_SLUG, mActivity.mProject.getSlug());
    metadata.put(SiteController.VALUE_KEY_BODY, mActivity.mProject.getDescription());
    metadata.put(SiteController.VALUE_KEY_TAGS, mActivity.mProject.getTagsAsString());
    String userName = getStoryMakerUserName();
    metadata.put(SiteController.VALUE_KEY_AUTHOR, userName);
    metadata.put(SiteController.VALUE_KEY_PROFILE_URL, "http://storymaker.org/" + userName);
    metadata.put(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_AUTHOR, shareAuthor ? "true" : "false");
    metadata.put(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_TITLE, shareTitle ? "true" : "false");
    metadata.put(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_TAGS, shareTags ? "true" : "false");
    metadata.put(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_DESCRIPTION, shareDescription ? "true" : "false");
    metadata.put(ArchiveMetadataActivity.INTENT_EXTRA_SHARE_LOCATION, shareLocation ? "true" : "false");
    metadata.put(ArchiveSiteController.VALUE_KEY_LICENSE_URL, licenseUrl);
    PublishJob publishJob = new PublishJob(getActivity().getBaseContext(), mActivity.mProject.getId(), mSiteKeys, (new Gson()).toJson(metadata));
    publishJob.save();
    startRender(publishJob);
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) PublishJob(org.storymaker.app.model.PublishJob)

Example 13 with PublishJob

use of org.storymaker.app.model.PublishJob in project storymaker by StoryMaker.

the class UploadWorker method start.

public void start(PublishJob publishJob) {
    //		// TODO guard against multiple calls if we are running already
    ////		ArrayList<Job> jobs = (ArrayList<Job>) (new JobTable(db)).getUnfinishedAsList(context, JobTable.TYPE_UPLOAD);
    //		Job job = (new JobTable(null)).getNextUnfinished(mContext, JobTable.TYPE_UPLOAD, publishJob, null); // FIXME this is grabbing incomplete jobs from previous runs, we should only run the ones from our current publishJob
    //		UploaderBase uploader = null;
    //		if (job != null) {
    //    		if (job.isSite(Auth.SITE_YOUTUBE)) {
    //    			uploader = new YoutubeUploader(mContext, this, job);
    //    		} else if (job.isSite(Auth.SITE_STORYMAKER)) {
    //                uploader = new StoryMakerUploader(mContext, this, job);
    //            } else if (job.isSite(Auth.SITE_FACEBOOK)) {
    //                uploader = new FacebookUploader(mContext, this, job);
    //            } else if (job.isSite(Auth.SITE_FLICKR)) {
    //                uploader = new FlickrUploader(mContext, this, job);
    //            } else if (job.isSite(Auth.SITE_SOUNDCLOUD)) {
    //                uploader = new SoundCloudUploader(mContext, this, job);
    //            } else if (job.isSite(Auth.SITE_SSH)) {
    //                uploader = new SSHUploader(mContext, this, job);
    //            } else if (job.isSite(Auth.SITE_ARCHIVE)) {
    //                uploader = new ArchiveUploader(mContext, this, job);
    //            } 
    //    		uploader.start();
    //		}
    // TODO guard against multiple calls if we are running already
    // FIXME extend this to multiple render jobs, for now its hard coded to 1 at a time
    Job job = publishJob.getUploadJobsAsList().get(0);
    UploaderBase uploader = null;
    if (job != null) {
        if (job.isSite(Auth.SITE_YOUTUBE)) {
            uploader = new YoutubeUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_STORYMAKER)) {
            uploader = new StoryMakerUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_FACEBOOK)) {
            uploader = new FacebookUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_FLICKR)) {
            uploader = new FlickrUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_SOUNDCLOUD)) {
            uploader = new SoundCloudUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_SSH)) {
            uploader = new SSHUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_ARCHIVE)) {
            uploader = new ArchiveUploader(mContext, this, job);
        } else if (job.isSite(Auth.SITE_S3)) {
            uploader = new S3Uploader(mContext, this, job);
        }
        uploader.start();
    }
}
Also used : SSHUploader(org.storymaker.app.publish.sites.SSHUploader) YoutubeUploader(org.storymaker.app.publish.sites.YoutubeUploader) FacebookUploader(org.storymaker.app.publish.sites.FacebookUploader) SoundCloudUploader(org.storymaker.app.publish.sites.SoundCloudUploader) ArchiveUploader(org.storymaker.app.publish.sites.ArchiveUploader) S3Uploader(org.storymaker.app.publish.sites.S3Uploader) PublishJob(org.storymaker.app.model.PublishJob) Job(org.storymaker.app.model.Job) FlickrUploader(org.storymaker.app.publish.sites.FlickrUploader) StoryMakerUploader(org.storymaker.app.publish.sites.StoryMakerUploader)

Example 14 with PublishJob

use of org.storymaker.app.model.PublishJob in project storymaker by StoryMaker.

the class FlickrUploader method start.

@Override
public void start() {
    Timber.d("start()");
    final SiteController controller = SiteController.getSiteController(FlickrSiteController.SITE_KEY, mContext, mHandler, "" + mJob.getId());
    final Project project = mJob.getProject();
    final PublishJob publishJob = mJob.getPublishJob();
    final String path = publishJob.getLastRenderFilePath();
    final Auth auth = (new AuthTable()).getAuthDefault(mContext, Auth.SITE_FLICKR);
    if (path != null) {
        Handler mainHandler = new Handler(mContext.getMainLooper());
        Runnable myRunnable = new Runnable() {

            @Override
            public void run() {
                Timber.d("run()");
                // FIXME, this might not be wise to run on the main thread flickr, does the flickr SDK automatically run itself on a backgroundthread?
                HashMap<String, String> valueMap = publishJob.getMetadata();
                // need to extract raw photos
                // what happened to STORY_TYPE_PHOTO?
                // TODO: currently checking preferences, will revisit when ui is updated
                SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
                boolean uploadPhotos = sharedPref.getBoolean("pphotoformat", false);
                if ((publishJob.getProject().getStoryType() == Project.STORY_TYPE_ESSAY) && uploadPhotos) {
                    ArrayList<Media> photos = publishJob.getProject().getMediaAsList();
                    String photoString = "";
                    for (Media photo : photos) {
                        photoString = photoString + photo.getPath() + ";";
                    }
                    // drop trailing ;
                    photoString = photoString.substring(0, photoString.length() - 1);
                    valueMap.put(FlickrSiteController.PHOTO_SET_KEY, photoString);
                }
                addValuesToHashmap(valueMap, project.getTitle(), project.getDescription(), path);
                controller.upload(auth.convertToAccountObject(), valueMap);
            }
        };
        mainHandler.post(myRunnable);
    } else {
        Timber.e("flickr upload failed, file path is null");
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) AuthTable(org.storymaker.app.model.AuthTable) Media(org.storymaker.app.model.Media) Handler(android.os.Handler) SiteController(io.scal.secureshare.controller.SiteController) FlickrSiteController(io.scal.secureshare.controller.FlickrSiteController) PublishJob(org.storymaker.app.model.PublishJob) Project(org.storymaker.app.model.Project) Auth(org.storymaker.app.model.Auth)

Example 15 with PublishJob

use of org.storymaker.app.model.PublishJob in project storymaker by StoryMaker.

the class S3Uploader method start.

// FIXME move the render file checks into base class
@Override
public void start() {
    // TODO Auto-generated constructor stub
    final SiteController controller = SiteController.getSiteController(S3SiteController.SITE_KEY, mContext, mHandler, "" + mJob.getId());
    final Project project = mJob.getProject();
    final PublishJob publishJob = mJob.getPublishJob();
    final String path = publishJob.getLastRenderFilePath();
    // FIXME deal with lack of auth credentials here
    if (Utils.stringNotBlank(path) && (new File(path)).exists()) {
        Handler mainHandler = new Handler(mContext.getMainLooper());
        Runnable myRunnable = new Runnable() {

            // facebook seems to freak out if our service's looper is dead when it tries to send message back 
            @Override
            public void run() {
                jobProgress(mJob, 0, mContext.getString(R.string.uploading));
                HashMap<String, String> valueMap = publishJob.getMetadata();
                addValuesToHashmap(valueMap, project.getTitle(), project.getDescription(), path);
                //                    controller.upload(auth.convertToAccountObject(), valueMap);
                controller.upload(null, valueMap);
            }
        };
        mainHandler.post(myRunnable);
    } else {
        Timber.d("Can't upload to S3, last rendered file doesn't exist.");
        // TODO get this error back to the activity for display 
        // FIXME move to strings.xml
        jobFailed(null, ERROR_NO_RENDER_FILE, "Can't upload to S3, last rendered file doesn't exist.");
    }
}
Also used : Project(org.storymaker.app.model.Project) Handler(android.os.Handler) SiteController(io.scal.secureshare.controller.SiteController) S3SiteController(io.scal.secureshare.controller.S3SiteController) File(java.io.File) PublishJob(org.storymaker.app.model.PublishJob)

Aggregations

PublishJob (org.storymaker.app.model.PublishJob)17 Project (org.storymaker.app.model.Project)7 Handler (android.os.Handler)6 SiteController (io.scal.secureshare.controller.SiteController)6 File (java.io.File)6 Auth (org.storymaker.app.model.Auth)6 AuthTable (org.storymaker.app.model.AuthTable)6 SharedPreferences (android.content.SharedPreferences)2 Job (org.storymaker.app.model.Job)2 Media (org.storymaker.app.model.Media)2 Gson (com.google.gson.Gson)1 ArchiveSiteController (io.scal.secureshare.controller.ArchiveSiteController)1 FacebookSiteController (io.scal.secureshare.controller.FacebookSiteController)1 FlickrSiteController (io.scal.secureshare.controller.FlickrSiteController)1 S3SiteController (io.scal.secureshare.controller.S3SiteController)1 SSHSiteController (io.scal.secureshare.controller.SSHSiteController)1 SoundCloudSiteController (io.scal.secureshare.controller.SoundCloudSiteController)1 HashMap (java.util.HashMap)1 ArchiveUploader (org.storymaker.app.publish.sites.ArchiveUploader)1 AudioRenderer (org.storymaker.app.publish.sites.AudioRenderer)1