Book a Campaign (SOAP)
This use case illustrates how to create and target a campaign, and associate it with an ad copy. In combination with the Import Content from a URL (SOAP) use case, it shows the complete set of operations required to ingest content, schedule it and have it appear on the targeted player systems.
The following stages correspond to the comments in the code samples.
To book a campaign (SOAP):
- Create a reservation. See reservation_mgr_add.
- Target the reservation to specific display units. See reservation_mgr_add_skin_slots.
- After you create the skin_slots, add content to the reservation first by fetching the default_schedule_id of the reservation we just created. See reservation_mgr_list_many.
- Create the bundle that will hold the content. See bundle_mgr_add.
- Associate a specific content_id to the bundle. Be sure to provide a valid content ID#. See bundle_content_mgr_add.
- Promote the campaign. See reservation_mgr_update.
Note: As is, the request will target all display units in the domain; however, by specifying criteria, containers and Boolean operators, you can fine-grain the targeting.
Note: The ID#s we use in these samples are for illustration purposes. They are invalid. Be sure to use your own ID#s for your integrations.
#!/usr/bin/php
<?php
## Book a new campaign (reservation)
##
## Usage: php reservation_mgr_add --domain=domainId --du_or_criteria="23 43 ..." [--content=adCopyId] [--container=folderId]
## Usage example : php reservation_mgr_add --domain=123456789 --du_or_criteria="123456789 987654321" --content=123456789 --container=987654321
include "soaplib.php";
include "cmdutil.php";
$options = get_arguments("domain!", "du_or_criteria!", "container", "content!");
/* First, create the reservation. */
$body = new stdClass();
$body -> domain_id = $options["domain"]; # ID of your domain
$body -> name = "Test_Reservation_using_resource_criteria_mgr_add";
$body -> container_id = @$options["container"];
$body -> duration_msec = 10000;
$body -> start_date = "2016-06-01";
$body -> end_date = "2016-12-31";
$body -> start_time = "00:00:00";
$body -> end_time = "23:59:59";
$response = performSimpleOperation("reservation", "add", 19, $body);
if (!$response) {
print "Could not create reservation.\n";
return;
}
/* Add targeting criteria to reservation. */
$reservation_id = $response -> reservation[0] -> id;
foreach (explode(" ", $options["du_or_criteria"]) as $criteria_id) {
$body = new stdClass();
$body -> parent_id = $reservation_id;
$body -> criteria_id = $criteria_id;
$body -> type = 5; // Display unit targeting; at least on required
$body -> domain_id = $options["domain"];
$criteria_response = performSimpleOperation("resource_criteria", "add", 7, $body, false);
}
/* Next, add all display units to the reservation. */
$body = new stdClass();
$body -> domain_id = $options["domain"];
$body -> id = $reservation_id;
# Pass criteria as space-separated IDs on the command line
$body -> du_or_criteria = array_map(function($a) {
return array("id" => $a);}, explode(" ", $options["du_or_criteria"]));
$response = performSimpleOperation("reservation", "add_skin_slots", 19, $body);
if (!$response) {
print "Could not create skin slots.\n";
return;
}
/* Now, we need to fetch the default schedule id of the created reservation. */
$body = new stdClass();
$body -> domain_id = $options["domain"];
$body -> ids = $reservation_id;
$response = performSimpleOperation("reservation", "list_many", 19, $body);
if (!$response) {
print "Could not list reservation.\n";
return;
}
/* Create the bundle that will hold the content. */
$body = new stdClass();
$body -> domain_id = $options["domain"];
$body -> parent_id = $response -> reservation[0] -> default_schedule_id;
$body -> name = "Broadsign_1280_720";
$response = performSimpleOperation("bundle", "add", 12, $body);
if (!$response) {
print "Could not add bundle.\n";
return;
}
/* Associate a specific content ID to the bundle. Ensure that your content ID is valid. */
$body = new stdClass();
$body -> domain_id = $options["domain"];
$body -> parent_id = $response -> bundle[0] -> id;
$body -> content_id = $options["content"];
$response = performSimpleOperation("bundle_content", "add", 5, $body);
if (!$response) {
print "Could not add content to bundle.\n";
return;
}
/* Promote the campaign. */
$body = new stdClass();
$body -> ids = $reservation_id;
$body -> domainId = $options["domain"];
$response = performSimpleOperation("reservation", "list_many", 19, $body);
if (!$response || !isset($response -> reservation[0])) {
print "Could not access reservation.\n";
return;
}
$reservation = $response -> reservation[0];
$body = $reservation;
$body -> state = 1; # State 1 means Contracted
$response = performSimpleOperation("reservation", "update", 19, $body);
if (!$response) {
print "Could not promote reservation.\n";
return;
}
?>
Note: The ID#s we use in these samples are for illustration purposes. They are invalid. Be sure to use your own ID#s for your integrations.
/*
* (c) 2002 - 2015 BroadSign International, LLC
*/
import java.util.Calendar;
import org.apache.axis2.Constants.Configuration;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
import org.apache.axis2.transport.http.HTTPConstants;
import com.broadsign.www.wsdl_ops.BsapiStub;
public class Main {
public static void main(String[] args) throws Exception {
/* Basic setup */
setupKeystore();
System.out.println("Keystore set up");
BsapiStub javaStub = createStub();
System.out.println("Stub set up");
// Here are some pre-existing resources
// An ad copy to include in the campaign
String basicAdCopy = "12345678";
// A criteria to use to target display units
String basicDisplayUnitCriteria = "12345678";
// A customer to place the campaign in
String basicCustomer = "12345678";
// Your domain's ID
String basicDomain = "12345678";
/* First, create the reservation */
Calendar startDate = Calendar.getInstance();
Calendar endDate;
Calendar startTime = Calendar.getInstance();
Calendar endTime;
String contentIds[] = new String[1];
CampaignFactory campaignFactory = new CampaignFactory(javaStub);
CampaignDefaults defaults = new CampaignDefaults();
CampaignTargeting targeting = new CampaignTargeting();
contentIds[0] = basicAdCopy;
startDate.add(Calendar.MONTH, 1);
endDate = (Calendar)startDate.clone();
endDate.add(Calendar.MONTH, 1);
startTime.set(Calendar.HOUR_OF_DAY, 0);
endTime = (Calendar)startTime.clone();
endTime.add(Calendar.HOUR_OF_DAY, 23);
defaults.defaultBundleWeight = 0;
defaults.defaultCategoryId = null;
defaults.defaultFullscreen = true;
defaults.defaultTriggerCategoryId = null;
/* Add targeting criteria to the reservation */
targeting.duAndCriteria.add(basicDisplayUnitCriteria);
campaignFactory.createCampaign("BroadSign SDK Campaign Test",
Util.calendarToDateString(startDate),
Util.calendarToDateString(endDate),
Util.calendarToTimeString(startTime),
Util.calendarToTimeString(endTime),
10000,
1,
defaults,
targeting,
basicCustomer,
contentIds,
basicDomain,
true);
}
private static BsapiStub createStub()
{
try {
ConfigurationContext config = ConfigurationContextFactory.createDefaultConfigurationContext();
TransportOutDescription transport = new TransportOutDescription("https_mutual_auth");
CommonsHTTPTransportSender sender = new CommonsHTTPTransportSender();
sender.init(config, transport);
BsapiStub javaStub = new BsapiStub();
transport.setSender(sender);
javaStub._getServiceClient().getOptions().setProperty(Configuration.CHARACTER_SET_ENCODING, "utf-16");
javaStub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");
javaStub._getServiceClient().getOptions().setTransportOut(transport);
return javaStub;
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return null;
}
private static void setupKeystore()
{
// NOTE: Make sure to update the folders where your keystore files are located
// as well as the actual passwords for your keystores
System.setProperty("javax.net.ssl.keyStoreType", "jks");
System.setProperty("javax.net.ssl.keyStore", "YOUR_SOAP_KEYSTORE_HERE.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SOAP_KEYSTORE_PASSWORD_HERE");
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.trustStore", "YOUR_TRUSTED_KEYSTORE_HERE.keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "YOUR_TRUSTED_KEYSTORE_PASSWORD_HERE");
}
}
/*
* (c) 2002 - 2015 BroadSign International, LLC
*/
/*
* CampaignFactory Class
*
* This class allows the creation of campaigns
*/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.xmlbeans.XmlObject;
import com.broadsign.www.wsdl_ops.BsapiStub;
import com.broadsign.www.wsdl_ops.BundleContentMgrAddRequestBody;
import com.broadsign.www.wsdl_ops.BundleMgrAddRequestBody;
import com.broadsign.www.wsdl_ops.BundleMgrAddResponseBody;
import com.broadsign.www.wsdl_ops.ContentMgrListManyResponseBody;
import com.broadsign.www.wsdl_ops.LoopSlotMgrListByReservationRequestBody;
import com.broadsign.www.wsdl_ops.LoopSlotMgrListByReservationResponseBody;
import com.broadsign.www.wsdl_ops.RequestDocument;
import com.broadsign.www.wsdl_ops.ReservationMgrAddRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrAddResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrAddSkinSlotsRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrAddSkinSlotsResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrBatchDropSkinSlotsRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrBatchDropSkinSlotsResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrListManyResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrListRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrListResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrListScopedRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrListScopedResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrRebookConfirmRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrRebookRequestBody;
import com.broadsign.www.wsdl_ops.ReservationMgrRebookResponseBody;
import com.broadsign.www.wsdl_ops.ReservationMgrUpdateRequestBody;
import com.broadsign.www.wsdl_ops.ResponseDocument;
import com.broadsign.www.wsdl_ops.ScheduleMgrAddRequestBody;
import com.broadsign.www.wsdl_ops.ScheduleMgrAddResponseBody;
import com.broadsign.www.wsdl_ops.WsdlRequest;
import com.broadsign.www.wsdl_ops.WsdlResponse;
import com.broadsign.www.wsdl_types.ReservationState;
import com.broadsign.www.wsdl_types.ScheduleGroup;
class CampaignDefaults {
public Boolean defaultFullscreen;
public String defaultCategoryId;
public String defaultSegmentCategoryId;
public int defaultBundleWeight;
public String defaultTriggerCategoryId;
}
class CampaignTargeting {
public List<String> duAndCriteria = new ArrayList<String>();
public List<String> duOrCriteria = new ArrayList<String>();
public List<String> duNotCriteria = new ArrayList<String>();
public List<String> frameAndCriteria = new ArrayList<String>();
public List<String> frameOrCriteria = new ArrayList<String>();
public List<String> frameNotCriteria = new ArrayList<String>();
}
class CampaignFactory {
public CampaignFactory(BsapiStub stub)
{
assert(stub != null);
m_stub = stub;
m_fetchFacade = new FetchFacade(m_stub);
}
public String createCampaign(String name,
String startDate,
String endDate,
String startTime,
String endTime,
int durationMSec,
int saturation,
CampaignDefaults defaults,
CampaignTargeting targeting,
String customerId,
String contentIds[],
String domainId,
Boolean promote)
{
return createCampaignInternal(name,
startDate,
endDate,
startTime,
endTime,
durationMSec,
saturation,
defaults,
targeting,
customerId,
contentIds,
domainId,
promote);
}
private String createCampaignInternal(String name,
String startDate,
String endDate,
String startTime,
String endTime,
int durationMSec,
int saturation,
CampaignDefaults defaults,
CampaignTargeting targeting,
String customerId,
String contentIds[],
String domainId,
Boolean promote)
{
String campaignId = "";
try {
ReservationMgrAddRequestBody reservationMgrAddRequestBody = ReservationMgrAddRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
reservationMgrAddRequestBody.setParentId(customerId);
reservationMgrAddRequestBody.setDefaultCategoryId(defaults.defaultCategoryId);
reservationMgrAddRequestBody.setDefaultFullscreen(defaults.defaultFullscreen);
reservationMgrAddRequestBody.setDefaultSegmentCategoryId(defaults.defaultSegmentCategoryId);
reservationMgrAddRequestBody.setDefaultBundleWeight(defaults.defaultBundleWeight);
reservationMgrAddRequestBody.setDefaultTriggerCategoryId(defaults.defaultTriggerCategoryId);
reservationMgrAddRequestBody.setDurationMsec(durationMSec);
reservationMgrAddRequestBody.setStartDate(startDate);
reservationMgrAddRequestBody.setEndDate(endDate);
reservationMgrAddRequestBody.setStartTime(startTime);
reservationMgrAddRequestBody.setEndTime(endTime);
reservationMgrAddRequestBody.setName(name);
reservationMgrAddRequestBody.setSaturation(saturation);
reservationMgrAddRequestBody.setDomainId(domainId);
wsdlRequest.setName("reservation_mgr_add");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(reservationMgrAddRequestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.reservation_mgr_add_v19(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getReservationArray();
if (bodies.length == 1) {
ReservationMgrAddResponseBody campaign = ReservationMgrAddResponseBody.Factory.parse(bodies[0].xmlText());
String reservedSkinSlotCampaignId = "";
campaignId = campaign.getId().toString();
reservedSkinSlotCampaignId = reserveCampaignSkinSlotsInternal(campaign.getId().toString(),
targeting.duAndCriteria,
targeting.duOrCriteria,
targeting.duNotCriteria,
targeting.frameAndCriteria,
targeting.frameOrCriteria,
targeting.frameNotCriteria,
domainId);
if (!reservedSkinSlotCampaignId.isEmpty()) {
ReservationMgrListManyResponseBody campaignHandle = m_fetchFacade.listCampaign(campaignId, domainId);
String createdScheduleId = "";
LoopSlotMgrListByReservationRequestBody loopSlotMgrListByReservationRequestBody = LoopSlotMgrListByReservationRequestBody.Factory.newInstance();
WsdlRequest wsdlLoopSlotRequest = WsdlRequest.Factory.newInstance();
RequestDocument loopSlotRequestDocument = RequestDocument.Factory.newInstance();
XmlObject loopSlotBodies[];
ResponseDocument loopSlotResponseDocument;
loopSlotMgrListByReservationRequestBody.setReservationId(campaignId);
loopSlotMgrListByReservationRequestBody.setDomainId(domainId);
wsdlLoopSlotRequest.setName("loop_slot_mgr_list_by_reservation");
wsdlLoopSlotRequest.setVersion(9);
wsdlLoopSlotRequest.setLoopSlot(loopSlotMgrListByReservationRequestBody);
loopSlotRequestDocument.setRequest(wsdlLoopSlotRequest);
loopSlotRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(loopSlotRequestDocument.xmlText());
loopSlotResponseDocument = m_stub.loop_slot_mgr_list_by_reservable_v9(loopSlotRequestDocument);
System.out.println(loopSlotResponseDocument.xmlText());
loopSlotBodies = loopSlotResponseDocument.getResponse().getLoopSlotArray();
if (loopSlotBodies.length == 1) {
LoopSlotMgrListByReservationResponseBody loopSlot = LoopSlotMgrListByReservationResponseBody.Factory.parse(loopSlotBodies[0].xmlText());
String loopSlotId = loopSlot.getId().toString();
createdScheduleId = addScheduleToCampaign(domainId, startDate, endDate, startTime, endTime, 127, campaignId, loopSlotId);
}
if (campaignHandle != null) {
for (int i = 0; i < contentIds.length; i++) {
if (!addContentToSchedule(campaignHandle.getDefaultScheduleId().toString(), contentIds[i], domainId))
System.out.println("Error: Failed to add content Id " + contentIds[i] + " to default schedule.");
if (!createdScheduleId.isEmpty()) {
if (!addContentToSchedule(createdScheduleId, contentIds[i], domainId))
System.out.println("Error: Failed to add content Id " + contentIds[i] + " to created schedule.");
}
}
if (!promoteReservation(campaignHandle))
System.out.println("Error: Failed to promote campaign.");
} else {
System.out.println("Error: Failed to list campaign.");
}
} else {
System.out.println("Error: Failed to reserve skin slots.");
}
} else {
System.out.println("Error: Failed to create campaign.");
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return campaignId;
}
public String reserveCampaignSkinSlots(String reservationId,
String domainId,
CampaignTargeting targeting)
{
return reserveCampaignSkinSlotsInternal(reservationId,
targeting.duAndCriteria,
targeting.duOrCriteria,
targeting.duNotCriteria,
targeting.frameAndCriteria,
targeting.frameOrCriteria,
targeting.frameNotCriteria,
domainId);
}
private String reserveCampaignSkinSlotsInternal(String reservationId,
List<String> duAndCriteria,
List<String> duOrCriteria,
List<String> duNotCriteria,
List<String> duAndFrame,
List<String> duOrFrame,
List<String> duNotFrame,
String domainId)
{
String campaignId = "";
try {
ReservationMgrAddSkinSlotsRequestBody requestBody = ReservationMgrAddSkinSlotsRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
for (Iterator<String> it = duAndCriteria.iterator(); it.hasNext();)
requestBody.addNewDuAndCriteria().setId(it.next());
for (Iterator<String> it = duOrCriteria.iterator(); it.hasNext();)
requestBody.addNewDuOrCriteria().setId(it.next());
for (Iterator<String> it = duNotCriteria.iterator(); it.hasNext();)
requestBody.addNewDuNotCriteria().setId(it.next());
for (Iterator<String> it = duAndFrame.iterator(); it.hasNext();)
requestBody.addNewFrameAndCriteria().setId(it.next());
for (Iterator<String> it = duOrFrame.iterator(); it.hasNext();)
requestBody.addNewFrameOrCriteria().setId(it.next());
for (Iterator<String> it = duNotFrame.iterator(); it.hasNext();)
requestBody.addNewFrameNotCriteria().setId(it.next());
requestBody.setId(reservationId);
requestBody.setDomainId(domainId);
wsdlRequest.setName("reservation_mgr_add_skin_slots");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(requestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.reservation_mgr_add_skin_slots_v19(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getReservationArray();
assert(bodies.length == 1);
if (bodies.length == 1) {
ReservationMgrAddSkinSlotsResponseBody campaign = ReservationMgrAddSkinSlotsResponseBody.Factory.parse(bodies[0].xmlText());
campaignId = campaign.getId().toString();
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return campaignId;
}
private Boolean addContentToSchedule(String scheduleId, String contentId, String domainId)
{
try {
BundleMgrAddRequestBody bundleRequestBody = BundleMgrAddRequestBody.Factory.newInstance();
WsdlRequest bundleWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument bundleRequestDocument = RequestDocument.Factory.newInstance();
XmlObject bundleBodies[];
ResponseDocument bundleResponseDocument;
ContentMgrListManyResponseBody content = m_fetchFacade.listContent(contentId, domainId);
bundleRequestBody.setName(content == null ? "Ad Copy" : content.getName());
bundleRequestBody.setParentId(scheduleId);
bundleRequestBody.setDomainId(domainId);
bundleWsdlRequest.setName("bundle_mgr_add");
bundleWsdlRequest.setVersion(12);
bundleWsdlRequest.setBundle(bundleRequestBody);
bundleRequestDocument.setRequest(bundleWsdlRequest);
bundleRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(bundleRequestDocument.xmlText());
bundleResponseDocument = m_stub.bundle_mgr_add_v12(bundleRequestDocument);
System.out.println(bundleResponseDocument.xmlText());
bundleBodies = bundleResponseDocument.getResponse().getBundleArray();
assert(bundleBodies.length == 1);
if (bundleBodies.length == 1) {
BundleContentMgrAddRequestBody bundleContentRequestBody = BundleContentMgrAddRequestBody.Factory.newInstance();
WsdlRequest bundleContentWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument bundleContentRequestDocument = RequestDocument.Factory.newInstance();
XmlObject bundleContentBodies[];
ResponseDocument bundleContentResponseDocument;
BundleMgrAddResponseBody bundle = BundleMgrAddResponseBody.Factory.parse(bundleBodies[0].xmlText());
bundleContentRequestBody.setParentId(bundle.getId().toString());
bundleContentRequestBody.setContentId(contentId);
bundleContentRequestBody.setDomainId(domainId);
bundleContentWsdlRequest.setName("bundle_content_mgr_add");
bundleContentWsdlRequest.setVersion(5);
bundleContentWsdlRequest.setBundleContent(bundleContentRequestBody);
bundleContentRequestDocument.setRequest(bundleContentWsdlRequest);
bundleContentRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(bundleContentRequestDocument.xmlText());
bundleContentResponseDocument = m_stub.bundle_content_mgr_add_v5(bundleContentRequestDocument);
System.out.println(bundleContentResponseDocument.xmlText());
bundleContentBodies = bundleContentResponseDocument.getResponse().getBundleContentArray();
assert(bundleContentBodies.length == 1);
if (bundleContentBodies.length == 1)
return true;
} else {
System.out.println("Error: Failed to create bundle content relationship");
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return false;
}
private Boolean promoteReservation(ReservationMgrListManyResponseBody campaign)
{
try {
ReservationMgrUpdateRequestBody reservationRequestBody = ReservationMgrUpdateRequestBody.Factory.newInstance();
WsdlRequest reservationWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument reservationRequestDocument = RequestDocument.Factory.newInstance();
ResponseDocument reservationResponseDocument;
XmlObject reservationBodies[];
reservationRequestBody.setParentId(campaign.getParentId());
reservationRequestBody.setId(campaign.getId());
reservationRequestBody.setActive(campaign.getActive());
reservationRequestBody.setContainerId(campaign.getContainerId());
reservationRequestBody.setDefaultBundleWeight(campaign.getDefaultBundleWeight());
reservationRequestBody.setDefaultCategoryId(campaign.getDefaultCategoryId());
reservationRequestBody.setDefaultFullscreen(campaign.getDefaultFullscreen());
reservationRequestBody.setDefaultSegmentCategoryId(campaign.getDefaultSegmentCategoryId());
reservationRequestBody.setDefaultTriggerCategoryId(campaign.getDefaultTriggerCategoryId());
reservationRequestBody.setDomainId(campaign.getDomainId());
reservationRequestBody.setName(campaign.getName());
reservationRequestBody.setState(ReservationState.X_1); // Reservation_STATE_CONTRACTED == 1
reservationWsdlRequest.setName("reservation_mgr_update");
reservationWsdlRequest.setVersion(19);
reservationWsdlRequest.setReservation(reservationRequestBody);
reservationRequestDocument.setRequest(reservationWsdlRequest);
reservationRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(reservationRequestDocument.xmlText());
reservationResponseDocument = m_stub.reservation_mgr_update_v19(reservationRequestDocument);
System.out.println(reservationResponseDocument.xmlText());
reservationBodies = reservationResponseDocument.getResponse().getReservationArray();
assert(reservationBodies.length == 1);
if (reservationBodies.length == 1)
return true;
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return false;
}
public Boolean rebookCampaign(String id,
String startDate,
String endDate,
String startTime,
String endTime,
int durationMSec,
int saturation,
int dayOfWeekMask,
String domainId)
{
try {
ReservationMgrRebookRequestBody reservationMgrRebookRequestBody = ReservationMgrRebookRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
reservationMgrRebookRequestBody.setId(id);
reservationMgrRebookRequestBody.setStartDate(startDate);
reservationMgrRebookRequestBody.setEndDate(endDate);
reservationMgrRebookRequestBody.setStartTime(startTime);
reservationMgrRebookRequestBody.setEndTime(endTime);
reservationMgrRebookRequestBody.setDurationMsec(durationMSec);
reservationMgrRebookRequestBody.setSaturation(saturation);
reservationMgrRebookRequestBody.setDayOfWeekMask(dayOfWeekMask);
reservationMgrRebookRequestBody.setDomainId(domainId);
wsdlRequest.setName("reservation_mgr_rebook");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(reservationMgrRebookRequestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.reservation_mgr_rebook_v19(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getReservationArray();
if (bodies.length == 1) {
ReservationMgrRebookResponseBody reservation = ReservationMgrRebookResponseBody.Factory.parse(bodies[0].xmlText());
String slotTransactionId = reservation.getId().toString();
ReservationMgrRebookConfirmRequestBody reservationMgrRebookConfirmRequestBody = ReservationMgrRebookConfirmRequestBody.Factory.newInstance();
WsdlRequest wsdlRebookConfirmRequest = WsdlRequest.Factory.newInstance();
RequestDocument rebookConfirmRequestDocument = RequestDocument.Factory.newInstance();
XmlObject rebookConfirmBodies[];
ResponseDocument rebookConfirmResponseDocument;
reservationMgrRebookConfirmRequestBody.setId(id);
reservationMgrRebookConfirmRequestBody.setDomainId(domainId);
reservationMgrRebookConfirmRequestBody.setSlotTransactionId(slotTransactionId);
wsdlRebookConfirmRequest.setName("reservation_mgr_rebook_confirm");
wsdlRebookConfirmRequest.setVersion(19);
wsdlRebookConfirmRequest.setReservation(reservationMgrRebookConfirmRequestBody);
rebookConfirmRequestDocument.setRequest(wsdlRebookConfirmRequest);
rebookConfirmRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(rebookConfirmRequestDocument.xmlText());
rebookConfirmResponseDocument = m_stub.reservation_mgr_rebook_confirm_v19(rebookConfirmRequestDocument);
System.out.println(rebookConfirmResponseDocument.xmlText());
rebookConfirmBodies = rebookConfirmResponseDocument.getResponse().getReservationArray();
if (rebookConfirmBodies.length == 1) {
return true;
} else {
System.out.println("Error: Failed to confirm campaign rebooking.");
}
} else {
System.out.println("Error: Failed to rebook campaign.");
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return false;
}
public List<String> dropCampaignSkinSlots(String reservationId, String domainId)
{
List<String> campaignIdsOfDroppedSkinSlots = new ArrayList<String>();
try {
ReservationMgrBatchDropSkinSlotsRequestBody reservationMgrBatchDropSkinSlotsRequestBody = ReservationMgrBatchDropSkinSlotsRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
reservationMgrBatchDropSkinSlotsRequestBody.setId(reservationId);
reservationMgrBatchDropSkinSlotsRequestBody.setDomainId(domainId);
wsdlRequest.setName("reservation_mgr_batch_drop_skin_slots");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(reservationMgrBatchDropSkinSlotsRequestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.reservation_mgr_batch_drop_skin_slots_v19(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getReservationArray();
if (bodies.length > 0) {
for (XmlObject body : bodies) {
ReservationMgrBatchDropSkinSlotsResponseBody campaigns = ReservationMgrBatchDropSkinSlotsResponseBody.Factory.parse(body.xmlText());
campaignIdsOfDroppedSkinSlots.add(campaigns.getId().toString());
}
} else {
System.out.println("Error: Failed to drop skin_slots.");
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return campaignIdsOfDroppedSkinSlots;
}
private String addScheduleToCampaign(String domainId,
String startDate,
String endDate,
String startTime,
String endTime,
int dayOfWeekMask,
String reservableId,
String loopSlotId)
{
String scheduleId = "";
try {
ScheduleMgrAddRequestBody scheduleRequestBody = ScheduleMgrAddRequestBody.Factory.newInstance();
WsdlRequest scheduleWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument scheduleRequestDocument = RequestDocument.Factory.newInstance();
XmlObject scheduleBodies[];
ResponseDocument scheduleResponseDocument;
scheduleRequestBody.setName("BroadSign SDK Schedule Test");
scheduleRequestBody.setDomainId(domainId);
scheduleRequestBody.setStartDate(startDate);
scheduleRequestBody.setEndDate(endDate);
scheduleRequestBody.setStartTime(startTime);
scheduleRequestBody.setEndTime(endTime);
scheduleRequestBody.setDayOfWeekMask(dayOfWeekMask);
scheduleRequestBody.setScheduleGroup(ScheduleGroup.X_2); // ScheduleGroup_LOOP_SLOT == 2
scheduleRequestBody.setReservableId(reservableId);
scheduleRequestBody.setParentId(loopSlotId);
scheduleWsdlRequest.setName("schedule_mgr_add");
scheduleWsdlRequest.setVersion(8);
scheduleWsdlRequest.setSchedule(scheduleRequestBody);
scheduleRequestDocument.setRequest(scheduleWsdlRequest);
scheduleRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(scheduleRequestDocument.xmlText());
scheduleResponseDocument = m_stub.schedule_mgr_add_v8(scheduleRequestDocument);
System.out.println(scheduleResponseDocument.xmlText());
scheduleBodies = scheduleResponseDocument.getResponse().getScheduleArray();
assert(scheduleBodies.length == 1);
if (scheduleBodies.length == 1) {
ScheduleMgrAddResponseBody schedule = ScheduleMgrAddResponseBody.Factory.parse(scheduleBodies[0].xmlText());
scheduleId = schedule.getId().toString();
} else {
System.out.println("Error: Failed to create schedule.");
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return scheduleId;
}
public List<String> listReservations(String domainId, String parentContainerIds, Boolean currentOnly) throws Exception
{
List<String> results = new ArrayList<String>();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
XmlObject xmlBodies[];
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
ResponseDocument responseDocument;
WsdlResponse response;
if (!parentContainerIds.isEmpty()) {
ReservationMgrListScopedRequestBody requestBody = ReservationMgrListScopedRequestBody.Factory.newInstance();
requestBody.setDomainId(domainId);
requestBody.setParentContainerIds(parentContainerIds);
requestBody.setCurrentOnly(currentOnly);
wsdlRequest.setName("reservation_mgr_list_scoped");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(requestBody);
} else {
ReservationMgrListRequestBody requestBody = ReservationMgrListRequestBody.Factory.newInstance();
requestBody.setDomainId(domainId);
requestBody.setCurrentOnly(currentOnly);
wsdlRequest.setName("reservation_mgr_list");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(requestBody);
}
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
if (!parentContainerIds.isEmpty())
responseDocument = m_stub.reservation_mgr_list_scoped_v19(requestDocument);
else
responseDocument = m_stub.reservation_mgr_list_v19(requestDocument);
System.out.println(responseDocument.xmlText());
response = responseDocument.getResponse();
xmlBodies = response.getReservationArray();
if (xmlBodies.length > 0) {
for (XmlObject xmlBody : xmlBodies) {
if (!parentContainerIds.isEmpty()) {
ReservationMgrListScopedResponseBody reservation = ReservationMgrListScopedResponseBody.Factory.parse(xmlBody.xmlText());
results.add(reservation.getId().toString());
} else {
ReservationMgrListResponseBody reservation = ReservationMgrListResponseBody.Factory.parse(xmlBody.xmlText());
results.add(reservation.getId().toString());
}
}
}
return results;
}
private BsapiStub m_stub = null;
private FetchFacade m_fetchFacade = null;
}
/*
* (c) 2002 - 2015 BroadSign International, LLC
*/
/*
* FetchFacade Class
*
* This class contains basic listing operations
*/
import java.util.ArrayList;
import java.util.List;
import org.apache.xmlbeans.*;
import com.broadsign.www.wsdl_ops.*;
class FetchFacade {
public FetchFacade(BsapiStub stub)
{
assert(stub != null);
m_stub = stub;
}
public RelationshipMgrListResponseBody[] listRelationshipsByLeftResourceId(String leftResourceId, String domainId)
{
List<RelationshipMgrListResponseBody> relationships = new ArrayList<RelationshipMgrListResponseBody>();
try {
RelationshipMgrListRequestBody relationshipRequestBody = RelationshipMgrListRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
relationshipRequestBody.setDomainId(domainId);
wsdlRequest.setName("relationship_mgr_list");
wsdlRequest.setVersion(5);
wsdlRequest.setRelationship(relationshipRequestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.relationship_mgr_list_v5(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getRelationshipArray();
for (int i = 0; i < bodies.length; i++) {
RelationshipMgrListResponseBody relationship = RelationshipMgrListResponseBody.Factory.parse(bodies[i].xmlText());
assert(relationship != null);
if (relationship != null && Integer.parseInt(relationship.getParentId().toString()) == Integer.parseInt(leftResourceId))
relationships.add(relationship);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return relationships.toArray(new RelationshipMgrListResponseBody[relationships.size()]);
}
public ContainerMgrListResponseBody[] listContainers(String ids[], String domainId)
{
List<ContainerMgrListResponseBody> containers = new ArrayList<ContainerMgrListResponseBody>();
try {
ContainerMgrListManyRequestBody containerRequestBody = ContainerMgrListManyRequestBody.Factory.newInstance();
WsdlRequest containerWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument containerRequestDocument = RequestDocument.Factory.newInstance();
XmlObject containerBodies[];
ResponseDocument containerResponseDocument;
String stringIds = Util.arrayToString(ids);
containerRequestBody.setIds(stringIds);
containerRequestBody.setDomainId(domainId);
containerWsdlRequest.setName("container_mgr_list_many");
containerWsdlRequest.setVersion(8);
containerWsdlRequest.setContainer(containerRequestBody);
containerRequestDocument.setRequest(containerWsdlRequest);
containerRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(containerRequestDocument.xmlText());
containerResponseDocument = m_stub.container_mgr_list_many_v8(containerRequestDocument);
System.out.println(containerResponseDocument.xmlText());
containerBodies = containerResponseDocument.getResponse().getContainerArray();
assert(containerBodies.length > 0);
for (int i = 0; i < containerBodies.length; i++) {
ContainerMgrListResponseBody container = ContainerMgrListResponseBody.Factory.parse(containerBodies[i].xmlText());
assert(container != null);
if (container != null)
containers.add(container);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return containers.toArray(new ContainerMgrListResponseBody[containers.size()]);
}
public CriteriaMgrListManyResponseBody[] listCriteria(String ids[], String domainId)
{
List<CriteriaMgrListManyResponseBody> criterias = new ArrayList<CriteriaMgrListManyResponseBody>();
try {
CriteriaMgrListManyRequestBody criteriaRequestBody = CriteriaMgrListManyRequestBody.Factory.newInstance();
WsdlRequest criteriaWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument criteriaRequestDocument = RequestDocument.Factory.newInstance();
XmlObject criteriaBodies[];
ResponseDocument criteriaResponseDocument;
String stringIds = Util.arrayToString(ids);
criteriaRequestBody.setIds(stringIds);
criteriaRequestBody.setDomainId(domainId);
criteriaWsdlRequest.setName("criteria_mgr_list_many");
criteriaWsdlRequest.setVersion(7);
criteriaWsdlRequest.setCriteria(criteriaRequestBody);
criteriaRequestDocument.setRequest(criteriaWsdlRequest);
criteriaRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(criteriaRequestDocument.xmlText());
criteriaResponseDocument = m_stub.criteria_mgr_list_many_v7(criteriaRequestDocument);
System.out.println(criteriaResponseDocument.xmlText());
criteriaBodies = criteriaResponseDocument.getResponse().getCriteriaArray();
assert(criteriaBodies.length > 0);
for (int i = 0; i < criteriaBodies.length; i++) {
CriteriaMgrListManyResponseBody criteria = CriteriaMgrListManyResponseBody.Factory.parse(criteriaBodies[i].xmlText());
assert(criteria != null);
if (criteria != null)
criterias.add(criteria);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return criterias.toArray(new CriteriaMgrListManyResponseBody[criterias.size()]);
}
public ResourceCriteriaMgrListResponseBody[] listResourceCriteriaByTargetResourceId(String targetResourceId, String domainId)
{
List<ResourceCriteriaMgrListResponseBody> rcs = new ArrayList<ResourceCriteriaMgrListResponseBody>();
try {
ResourceCriteriaMgrListRequestBody rcRequestBody = ResourceCriteriaMgrListRequestBody.Factory.newInstance();
WsdlRequest rcWsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument rcRequestDocument = RequestDocument.Factory.newInstance();
XmlObject rcBodies[];
ResponseDocument rcResponseDocument;
rcRequestBody.setParentId(targetResourceId);
rcRequestBody.setDomainId(domainId);
rcWsdlRequest.setName("resource_criteria_mgr_list");
rcWsdlRequest.setVersion(7);
rcWsdlRequest.setResourceCriteria(rcRequestBody);
rcRequestDocument.setRequest(rcWsdlRequest);
rcRequestDocument.documentProperties().setEncoding("utf-16");
System.out.println(rcRequestDocument.xmlText());
rcResponseDocument = m_stub.resource_criteria_mgr_list_v7(rcRequestDocument);
System.out.println(rcResponseDocument.xmlText());
rcBodies = rcResponseDocument.getResponse().getResourceCriteriaArray();
for (int i = 0; i < rcBodies.length; i++) {
ResourceCriteriaMgrListResponseBody rc = ResourceCriteriaMgrListResponseBody.Factory.parse(rcBodies[i].xmlText());
assert(rc != null);
if (rc != null)
rcs.add(rc);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return rcs.toArray(new ResourceCriteriaMgrListResponseBody[rcs.size()]);
}
public MediaPackageMgrListManyResponseBody listMediaPackage(String id, String domainId)
{
String ids[] = new String[1];
MediaPackageMgrListManyResponseBody mediaPackages[];
ids[0] = id;
mediaPackages = listMediaPackages(ids, domainId);
if (mediaPackages.length == 1)
return mediaPackages[0];
return null;
}
public MediaPackageMgrListManyResponseBody[] listMediaPackages(String ids[], String domainId)
{
List<MediaPackageMgrListManyResponseBody> mediaPackages = new ArrayList<MediaPackageMgrListManyResponseBody>();
try {
MediaPackageMgrListManyRequestBody mediaPackageRequestBody = MediaPackageMgrListManyRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
String stringIds = Util.arrayToString(ids);
mediaPackageRequestBody.setIds(stringIds);
mediaPackageRequestBody.setDomainId(domainId);
wsdlRequest.setName("media_package_mgr_list_many");
wsdlRequest.setVersion(9);
wsdlRequest.setMediaPackage(mediaPackageRequestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.media_package_mgr_list_many_v9(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getMediaPackageArray();
for (int i = 0; i < bodies.length; i++) {
MediaPackageMgrListManyResponseBody mediaPackage = MediaPackageMgrListManyResponseBody.Factory.parse(bodies[i].xmlText());
assert(mediaPackage != null);
if (mediaPackage != null)
mediaPackages.add(mediaPackage);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return mediaPackages.toArray(new MediaPackageMgrListManyResponseBody[mediaPackages.size()]);
}
public ReservationMgrListManyResponseBody listCampaign(String id, String domainId)
{
String ids[] = new String[1];
ReservationMgrListManyResponseBody bodies[];
ids[0] = id;
bodies = listCampaigns(ids, domainId);
if (bodies.length == 1)
return bodies[0];
return null;
}
public ReservationMgrListManyResponseBody[] listCampaigns(String ids[], String domainId)
{
List<ReservationMgrListManyResponseBody> campaigns = new ArrayList<ReservationMgrListManyResponseBody>();
try {
ReservationMgrListManyRequestBody requestBody = ReservationMgrListManyRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
String stringIds = Util.arrayToString(ids);
requestBody.setIds(stringIds);
requestBody.setDomainId(domainId);
wsdlRequest.setName("reservation_mgr_list_many");
wsdlRequest.setVersion(19);
wsdlRequest.setReservation(requestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.reservation_mgr_list_many_v19(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getReservationArray();
for (int i = 0; i < bodies.length; i++) {
ReservationMgrListManyResponseBody campaign = ReservationMgrListManyResponseBody.Factory.parse(bodies[i].xmlText());
assert(campaign != null);
if (campaign != null)
campaigns.add(campaign);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
return campaigns.toArray(new ReservationMgrListManyResponseBody[campaigns.size()]);
}
public ContentMgrListManyResponseBody listContent(String id, String domainId)
{
String ids[] = new String[1];
ContentMgrListManyResponseBody bodies[];
ids[0] = id;
bodies = listContents(ids, domainId);
if (bodies.length == 1)
return bodies[0];
return null;
}
public ContentMgrListManyResponseBody[] listContents(String ids[], String domainId)
{
List<ContentMgrListManyResponseBody> contents = new ArrayList<ContentMgrListManyResponseBody>();
assert(ids.length > 0);
if (ids.length > 0) {
try {
ContentMgrListManyRequestBody requestBody = ContentMgrListManyRequestBody.Factory.newInstance();
WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
RequestDocument requestDocument = RequestDocument.Factory.newInstance();
XmlObject bodies[];
ResponseDocument responseDocument;
String stringIds = Util.arrayToString(ids);
requestBody.setIds(stringIds);
requestBody.setDomainId(domainId);
wsdlRequest.setName("content_mgr_list_many");
wsdlRequest.setVersion(10);
wsdlRequest.setContent(requestBody);
requestDocument.setRequest(wsdlRequest);
requestDocument.documentProperties().setEncoding("utf-16");
System.out.println(requestDocument.xmlText());
responseDocument = m_stub.content_mgr_list_many_v10(requestDocument);
System.out.println(responseDocument.xmlText());
bodies = responseDocument.getResponse().getContentArray();
for (int i = 0; i < bodies.length; i++) {
ContentMgrListManyResponseBody content = ContentMgrListManyResponseBody.Factory.parse(bodies[i].xmlText());
assert(content != null);
if (content != null)
contents.add(content);
}
} catch (java.lang.Exception e) {
System.out.println("Error:" + e.toString());
}
}
return contents.toArray(new ContentMgrListManyResponseBody[contents.size()]);
}
private BsapiStub m_stub = null;
}
/*
* (c) 2002 - 2015 BroadSign International, LLC
*/
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
class Util {
public static String arrayToString(String ids[])
{
String stringIds = "";
for (int i = 0; i < ids.length; i++) {
if (!stringIds.isEmpty())
stringIds += ",";
stringIds += ids[i];
}
return stringIds;
}
public static Calendar dateStringToCalendar(String date) throws ParseException
{
Calendar c = Calendar.getInstance();
if (date != null) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date d = formatter.parse(date);
c.setTime(d);
}
return c;
}
public static String calendarToDateString(Calendar date)
{
if (date != null) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date.getTime());
}
return "";
}
public static String calendarToTimeString(Calendar date)
{
if (date != null) {
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
return formatter.format(date.getTime());
}
return "";
}
}