001 /*
002 * file CreateActivityDemo.java
003 *
004 * Licensed Materials - Property of IBM
005 * Restricted Materials of IBM - you are allowed to copy, modify and
006 * redistribute this file as part of any program that interfaces with
007 * IBM Rational CM API.
008 *
009 * com.ibm.rational.stp.client.samples.CreateActivityDemo
010 *
011 * © Copyright IBM Corporation 2008. All Rights Reserved.
012 * Note to U.S. Government Users Restricted Rights: Use, duplication or
013 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
014 */
015
016 package com.ibm.rational.stp.client.samples.cc;
017
018 import java.util.Date;
019
020 import javax.wvcm.PropertyRequestItem.PropertyRequest;
021
022 import com.ibm.rational.wvcm.stp.StpLocation;
023 import com.ibm.rational.wvcm.stp.StpLocation.Namespace;
024 import com.ibm.rational.wvcm.stp.StpProvider.Domain;
025 import com.ibm.rational.wvcm.stp.cc.CcActivity;
026 import com.ibm.rational.wvcm.stp.cc.CcProvider;
027 import com.ibm.rational.wvcm.stp.cc.CcStream;
028
029 /**
030 * Create a new UCM activity in an existing UCM development stream.
031 * Demonstrates WVCM's resource creation convention.
032 * Also demonstrates how to construct resource locations and proxies.
033 * as well as setting property values via "setter" methods.
034 */
035 public class CreateActivityDemo extends CcDemoBase {
036
037 /**
038 * Create a new UCM activity in the development stream.
039 */
040 public void testMakeActivity() throws Exception {
041
042 UcmHelper ucmHelper = new UcmHelper(this);
043 CcProvider provider = getClearCaseProvider();
044
045 // Get the development stream in which we'll create the new activity.
046 CcStream devStream = ucmHelper.getUcmDevelopmentStream();
047
048 // Create a location for the new activity.
049 String pvobName = props().getDemoUcmProjectVob();
050 StpLocation newActLoc = provider.userFriendlySelector(
051 Domain.CLEAR_CASE,
052 Namespace.ACTIVITY,
053 "", // activity name is auto-generated; see below
054 pvobName);
055
056 // Create a proxy for the new activity from the above location
057 // Note: This does *not* create the activity - that happens below.
058 // If we tried to use this proxy now, we would get a "NOT_FOUND" error.
059 CcActivity newAct = provider.ccActivity(newActLoc);
060
061 // Set the properties we want this activity to have when it's created.
062 newAct.setStream(devStream);
063 newAct.setHeadline("This is a new activity: " + new Date());
064
065 // The properties of the new activity we're interested in.
066 PropertyRequest wantedProps = new PropertyRequest(
067 CcActivity.DISPLAY_NAME,
068 CcActivity.HEADLINE,
069 CcActivity.STREAM.nest(
070 CcStream.DISPLAY_NAME
071 ));
072
073 // Now ask the server to actually create the activity.
074 // Note that "doCreateGeneratedCcActivity()" automatically generates
075 // a unique name for the new activity so we don't have to.
076 // Note also that we're making a property request at the same time
077 // we're creating the activity. This saves an extra round-trip
078 // to the server and simplifies our code a bit.
079 // Extra credit question: What is the purpose of the "newAct = " piece
080 // of this statement?
081 newAct = newAct.doCreateGeneratedCcActivity(wantedProps);
082
083 // Print new activity's properties
084 trace("New activity name: " + newAct.getDisplayName());
085 trace("New activity headline: " + newAct.getHeadline());
086 trace("New activity parent stream: " + newAct.getStream().getDisplayName());
087 }
088 }