Extensis Logo SUPPORT | FORUMS | KNOWLEDGE BASE

PHP Code Help - Job Query


#1

Hello , I am Monika Patel from Vertu Technology

I need some assistant in understanding how the job query work. I have written below code that have job query component to allow job query status report as part of the script.

The code that I wrote is based on code example provided.
When I ran the code, and I saw the job status ouput on Portfolio Webclient.

So, I would like to understand is how to get output on PHP Page.
Another matter I would like to understand is How to resize the image to Constraint 800px with 72 DPI resolution and download the images on user given Location.

Below is a copy of the code

[code]// Sample PHP script for accessing the Portfolio Server Resize all image and download all Images

<?php //include('sys:/IPTCMetadata.ms'); include('Crypt/RSA.php'); require_once 'AssetSEIService.php'; //$kNameHeader = "Portfolio-Output-Filename"; //Create Service for accessing the Portfolio Server. $service = new AssetSEIService(); // Use getRSAPublicEncryptionKey to get the Key Specification for encrypting the password. $getRSA = new getRSAPublicEncryptionKey(); $RSAresponse = $service->getRSAPublicEncryptionKey($getRSA); $key = $RSAresponse->return; // Encrypt the password $password = "password"; $ePassword = encrypt($password, $key); // Pass the username and the encrypted password through the login method. // This will return a Session-ID, which can be used to access other API services. $login = new login(); $login->userName = "administrator"; $login->encryptedPassword = $ePassword; $response = new loginResponse(); $response = $service->login($login); $sessionId = $response->return; //echo "$sessionId\n"; //echo "
"; // Function to encrypt the password function encrypt($password, $keySpec) { $m = new Math_BigInteger($keySpec->modulusBase16, 16); $e = new Math_BigInteger($keySpec->exponent); $rsa = new Crypt_RSA(); $publickey = array( "modulus" => $m, "e" => $e); $rsa->loadKey($publickey, CRYPT_RSA_PUBLIC_FORMAT_RAW); $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1); $epass = base64_encode($rsa->encrypt($password)); return $epass; } // Create an AssetQuery. This will perform a search. $aQuery = new AssetQuery("demo"); $assetQueryResultsOptions = new assetQueryResultOptions(); //Pagewise result $index = 0; $assetQueryResultsOptions = new assetQueryResultOptions(); $assetQueryResultsOptions->startingIndex = $index; $assetQueryResultsOptions->fieldNames = array( 0 => "Thumbnail" ); // Submit the query to get a new page of results. $getAssets = new getAssets(); $catalogId="930B41EC-B3C3-6BFE-0289-7B018005BB50"; $getAssets->catalogId = $catalogId; $getAssets->sessionId = $sessionId; $getAssets->assets = $aQuery;; $getAssets->resultOptions = $assetQueryResultsOptions; $Results = $service->getAssets($getAssets); $AssetsResults = $Results->return; $totalAssets = $AssetsResults->totalNumberOfAssets; echo "
Total Assets found: $totalAssets\n"; //My JOB of Resize //Create new Job $myJob = new job(); $myJob->sourceImage = SourceImage::ORIGINAL; // Convert the assets to jpegs and resize them //Tasks describe the procedure applied by the Job. //A job can contain multiple tasks. $convertTask = new Task(); $convertTask->type = TaskType::CONVERT; $convertSettings = array( 0 => buildAtt(TaskSetting::OUTPUT_FILE_FORMAT, OutputFileFormat::JPEG), 1 => buildAtt(TaskSetting::COLOR_MODE, ColorMode::RGB), 2 => buildAtt(TaskSetting::RESIZE_TYPE, ResizeType::FIT_WITHIN), 3 => buildAtt(TaskSetting::RESIZE_HEIGHT, "800"), 4 => buildAtt(TaskSetting::RESIZE_WIDTH, "600"), 5 => buildAtt(TaskSetting::RESIZE_UNITS, Unit::PIXELS) ); $convertTask->settings = $convertSettings; // Rename them $renameTask = new Task(); $renameTask->type = TaskType::RENAME; $renameSettings = array( 0 => buildAtt(TaskSetting::AUTO_RENAME, null), 1 => buildAtt(TaskSetting::FRONT_RENAME_TYPE, renameType::TEXT), 2 => buildAtt(taskSetting::FRONT_RENAME_VALUE, "TWCO"), 3 => buildAtt(TaskSetting::MIDDLE_RENAME_TYPE, renameType::FILENAME) ); $renameTask->settings = $renameSettings; // Download them as an archive $downloadTask = new Task(); $downloadTask->type = TaskType::DOWNLOAD; $downloadTask->settings = array( ); // You must specify an array, even if there are no settings to apply. // Collect the tasks and add them to the Job $myJob->tasks = array(0 => $convertTask, 1 => $renameTask, 2 => $downloadTask); // Run the Job $runJob = new runJob(); $runJob->sessionId = $sessionId; $runJob->catalogId = $catalogId; $runJob->assets = $aQuery; $runJob->job = $myJob; $jobResponse = $service->runJob($runJob); $myJobId = $jobResponse->return; echo("
Job ID:--$myJobId"); // myJob is now queued or running on the server. // It may be monitored for status, cancelled, queried for errors, etc. // Check the Job's status $getJobStatus = new getStatusForJobs(); $getJobStatus->jobIds = $myJobId; $getJobStatus->sessionId = $sessionId; $jobStatusResponse = $service->getStatusForjobs($getJobStatus); $jobStatus = $jobStatusResponse->return; echo("
Job Status : $jobStatus->status"); /* // Is the Job complete? echo("
Job status ---- >$jobStatus->status
"); if ($jobStatus->status == JobStatusType::COMPLETE ) { echo("
Job status ---- >$jobStatus->status
"); foreach ($jobStatus->jobDetails as $attr) { echo("$attr->name
"); if ($attr->name == "downloadLocation") { echo "Job Completed\n"; echo "Finished at $jobStatus->timeCompleted
"; echo "Download location: $attr->value
"; break; } } } // alert user their job was completed and ready to download // Is the Job in progress? elseif ($jobStatus->status == JobStatusType::IN_PROGRESS) { echo("
Job status ---- >$jobStatus->status
"); foreach ($jobStatus->jobDetails as $attr) { if ($attr->name == "currentIndex") { $currentFile = $attr->value; echo "Still in progress
"; echo "Current File number: $currentFile
"; } elseif ($attr->name == "totalFiles") { $totalFiles = $attr->value; echo "Total Files: $totalFiles
"; echo "=========================
"; } } // report progress to user } //End of my Resize Job */ echo ""; $ct=0; echo ""; foreach ( $AssetsResults->assets as $item) { // print("\n$item->assetId\n "); //echo "
"; $oneAsset=$item->attributes; $image = data_uri($oneAsset->values,'image/jpeg'); if($ct>2) { $ct=0; echo ""; } else { echo ""; echo ""; $ct++; } //echo "
"; //echo "
"; } echo "
"; // The data_uri function function data_uri($file, $mime) { $base64 = $file; return ('data:' . $mime . ';base64,' . $base64); } function buildAtt($name, $value ) { $attribute = new attribute(); $attribute->name = $name; if ($value) { $attribute->value = $value; } return $attribute; } echo "
"; $logout = new logout(); $logout->sessionId = $sessionId; $service->logout($logout); ?>

[/code]

Looking forward to your reply.

Thank you.
Monika Patel
(Vertu Technology Staff)


#2

Greetings Monika,
I’ll do my best to answer your questions.

I’m sorry, but I am not sure I understand what you mean with this question. Is your current code not displaying your results? Are you trying to view this code in an Web Browser?
If you wish to view a link to download the converted file, you can do something like this.

// Is the Job complete?
echo("<br>Job status ---- >$jobStatus->status<br>\n");
$complete = false;
while (! $complete) {
    if ($jobStatus->status == JobStatusType::COMPLETE ) {
        $complete = true;
        echo("<br>Job status ---- >$jobStatus->status<br>\n");
        foreach ($jobStatus->jobDetails as $attr) {
            if ($attr->name == "downloadLocation") {
                echo "Job Completed\n";
                echo "Finished at $jobStatus->timeCompleted <br>\n";
                $downloadLocation = $attr->value;
                $downloadURL = "http://$SERVER_ADDRESS:$SERVER_PORT$downloadLocation&sessionId=$sessionId";
                echo "Download URL: <a href=$downloadURL>CompletedJob</a>\n";
                break;
            }
        }
    }
    $jobStatusResponse = $service->getStatusForjobs($getJobStatus);
    $jobStatus = $jobStatusResponse->return;
}

Your code almost has the answer to this, you just need to specify a Resolution and a Resolution_Units. Here is an example.

$convertTask = new Task();
$convertTask->type = TaskType::CONVERT;
$convertSettings = array(
    0 => buildAtt(TaskSetting::OUTPUT_FILE_FORMAT, OutputFileFormat::JPEG),
    1 => buildAtt(TaskSetting::COLOR_MODE, ColorMode::RGB),
    2 => buildAtt(TaskSetting::RESIZE_TYPE, ResizeType::FIT_WITHIN),
    3 => buildAtt(TaskSetting::RESIZE_HEIGHT, "800"),
    4 => buildAtt(TaskSetting::RESIZE_WIDTH, "600"),
    5 => buildAtt(TaskSetting::RESIZE_UNITS, Unit::PIXELS),
    6 => buildAtt(TaskSetting::RESOLUTION, "72"),
    7 => buildAtt(TaskSetting::RESOLUTION_UNITS, Unit::INCHES)
);
$convertTask->settings = $convertSettings;

By the way, at the beginning of your code, I would recommend changing the line where you create the Asset Service.
Replace this line:

with this:

[quote]$SERVER_ADDRESS = “127.0.0.1”; //or the server IP address.
$SERVER_PORT = “8090”;
$service = new AssetSEIService(“http://$SERVER_ADDRESS:$SERVER_PORT/ws/1.0/AssetService?wsdl”);
[/quote]

If you have any other questions, please let me know.

Kind Regards,
-Matt