Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How i will use custom attribute for auto creation of a snapshot on stream after deliver change sets to it.(only for few stream not for all the stream which is present on server.

 I'm writing an operation(com.ibm.team.scm.server.deliver) participant that auto creates a snapshot for stream after deliver change sets to it.

but i don't want this feature for all the stream, i want for 2 to 3 stream as per user selection. How i will use custom attribute for this requirment.

Below sample code will applicable for create snapshot for all the stream:

public class AutoTakeSnapshotParticipant extends AbstractService implements IOperationParticipant {

public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
try {
//Check if is necessary to create snapshot
Object operationData = operation.getOperationData();
boolean isCheck = false;
DeliverOperationData data = null;
IScmDeltaSource deltaSrc = null;
if(operationData instanceof DeliverOperationData )
{
data = (DeliverOperationData) operationData;
isCheck = true;
} else if( operationData instanceof IScmDeltaSource ) {
deltaSrc = (IScmDeltaSource) operationData;
isCheck = true;
}
if (!isCheck) {
return;
}
//Get Service I need
IRepositoryItemService rService = getService(IRepositoryItemService.class);
IScmService scm = getService(IScmService.class);   
if (data != null) {
System.out.println(data.getSourceWorkspace().getName());
System.out.println(data.getDestWorkspace().getName());
IWorkspace destWs = data.getDestWorkspace();
if (destWs.isStream()) {
System.out.println(destWs.isImmutable());
}
Date d = new Date(System.currentTimeMillis());
WorkspaceItemListResult result = scm.createBaselineSet2(destWs, new IComponentHandle[0], 
d.toString(), d.toString() + "SnapShot", NONE, 
null, null, null);
// WorkspaceRefreshParameter wrp = IScmService.DELTA_PER_INVOCATION;
//scm.refreshWorkspaces(new WorkspaceRefreshParameter[] {wrp}, null);
System.out.println(result.getItems().size());
if (!result.getItems().isEmpty()) { 
IBaselineSet baselineSet = (IBaselineSet) result.getItems().get(0);
System.out.println(baselineSet);
}

} catch (Exception e) {
e.printStackTrace();
collector.addInfo(collector.createExceptionInfo("Exception Occurs in follow-up action: " + e.getMessage(), e));
}
}
}

0 votes

Comments
You might need to elaborate on what your question is, as it is not really clear. What is the exact issue you are facing?

@David Lafreniere
my Question is how i will get custom attribute value are only available on Streams and not Repository Workspaces. these are pre-defined by a Project Administrator in the Project Area configuration page (in the Web UI).
When you open  the Web UI Project Area configuration page, on the left hand navigator, click 'Source Control' --> 'Attribute Definition' and confirm that there are custom attributes available for a Stream.
i want to get those value via java API for server side plugin, how i will get those values? few lines of code can help here a lot.



One answer

Permanent link
IWorkspace.getCustomAttributes(); is the API to call on both the client and server to get (read) the custom attributes on a stream. This list will only return the custom attributes that were set on that stream, and not return a list of every custom attribute that is available for stream item types.


If you want to 'set' custom attributes on a Stream using server code, see:
   IScmService.setWorkspaceCustomAttributes(
         IWorkspaceHandle stream,
         IGenericAttributes attributesToAdd,
         String[] attributesToRemove,
         ISynchronizationTimes[] syncTimes,
         IRepositoryProgressMonitorHandle monitor)

If you want to 'set' custom attributes on a Stream using client-side code, see:
   IWorkspaceConnection.setCustomAttributes(
         Map<String, Object> attributesToAdd,
         String[] attributesToRemove,
         IProgressMonitor monitor)

You can also manually use the SCM command-line (CLI) to set specific custom attributes on specific stream.
Also in RTC 6.0.6 there is some UI right in the Snapshot editor that allow you to manage (add/edit/remove) custom attributes on that stream.

Also, see the following article by Ralph that shows programming examples related to SCM custom attributes: https://rsjazz.wordpress.com/2016/02/04/setting-custom-attributes-for-scm-versionables/


In RTC 6.0.6, server-side API was added to IScmService that will return the list of custom attributes that are available on a given project area.
The API and Javadoc is shown below:
    /
     * Return the defined custom attribute identifiers for the given type in the given project area.
    
     * @param projectArea
    
            The project area. Never {@code null}.
     * @param artifactType
                 The artifact type. One of:
    
            <ul>
                 <li>{@link CustomAttributeConstants#ARTIFACT_FILE}</li>
    
            <li>{@link CustomAttributeConstants#ARTIFACT_STREAM}</li>
                 <li>{@link CustomAttributeConstants#ARTIFACT_BASELINE}</li>
    
            <li>{@link CustomAttributeConstants#ARTIFACT_BASELINE_SET}</li>
                 <li>{@link CustomAttributeConstants#COMPONENT}</li>
    
            </ul>
     * @param monitor
                 A repository progress monitor, may be {@code null} if
    
            progress reporting and cancellation is not required.
    
     * @return the defined attribute identifiers.
    

     * @throws TeamRepositoryException
    
     * @since 0.11.0.6 (RTC 6.0.6)
    

     * @see CustomAttributeConstants
     */
    public String[] getDefinedCustomAttributeIdentifiers(
         IProjectAreaHandle projectArea,
         int artifactType,
         IRepositoryProgressMonitorHandle monitor)
               throws TeamRepositoryException;



In RTC 6.0.6, client-side API was added to IWorkspaceManager that will return the list of custom attributes that are available on a given project area.
The API and Javadoc is shown below:
    /
     * Return the defined custom attribute identifiers for the given type in the given project area.
    
     * @param projectArea
    
            The project area. Never {@code null}.
     * @param artifactType
                 The artifact type. One of:
    
            <ul>
                 <li>{@link CustomAttributeConstants#ARTIFACT_FILE}</li>
    
            <li>{@link CustomAttributeConstants#ARTIFACT_STREAM}</li>
                 <li>{@link CustomAttributeConstants#ARTIFACT_BASELINE}</li>
    
            <li>{@link CustomAttributeConstants#ARTIFACT_BASELINE_SET}</li>
                 <li>{@link CustomAttributeConstants#COMPONENT}</li>
    
            </ul>
     * @param monitor
                 A progress monitor, or {@code null} if progress reporting is not desired.
    

     * @return the defined attribute identifiers.
    
     * @throws TeamRepositoryException
    

     * @LongOp This is a long operation; it may block indefinitely; must not be
              called from a responsive thread.
    

     * @since 0.11.0.6 (RTC 6.0.6)
     */
    public String[] getDefinedCustomAttributeIdentifiers(
         IProjectAreaHandle projectArea,
         int type,
         IProgressMonitor monitor)
               throws TeamRepositoryException;

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938
× 1,700

Question asked: Aug 26 '18, 1:21 p.m.

Question was seen: 2,396 times

Last updated: Sep 05 '18, 10:37 a.m.

Confirmation Cancel Confirm