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

when we set custom attribute for stream in web UI. how to get those custom attrbute value in java (in SCM )

I am checking the RTC 6.0.5 feature.When in the Web UI Project Area configuration page, on the left hand navigator, click 'Source Control' --> 'Attribute Definition' and configure custom attribute value for a Stream as below figure.

Now i am trying to get the custom attribute via java code for server side extension(below is plugin code),but  I am not able to get custom attribute value, what i set in the UI (mention in above figure).

public void run(final AdvisableOperation operation, final IProcessConfigurationElement participantConfig,
      final IParticipantInfoCollector collector, final IProgressMonitor monitor) throws TeamRepositoryException {
    try {
      Object operationData = operation.getOperationData();
      DeliverOperationData deliveryData = null;
      IScmDeltaSource scmDeltaSrc = null;
      if (operationData instanceof DeliverOperationData) {
        deliveryData = (DeliverOperationData) operationData;
      }
      // Get Service I need
      IScmService scmService = getService(IScmService.class);
      if (deliveryData != null) {
         System.out.println(deliveryData.getSourceWorkspace().getName());
         System.out.println(deliveryData.getDestWorkspace().getName());
        IWorkspace destWorkspace = deliveryData.getDestWorkspace();
        String streamName = destWorkspace.getName();
        if (destWorkspace.isStream()) {
          System.out.println(streamName);
          System.out.println(destWorkspace.isImmutable());
        }
         // to get the custom attributes of the stream
        Map<String, Object> customAttributes = destWorkspace.getCustomAttributes();
        Set<String> keySet = customAttributes.keySet();
        for (String key : keySet) {
          System.out.println(key + ": " + customAttributes.get(key));
          }
          }
    catch (Exception e) {
      e.printStackTrace();
      collector.addInfo(collector.createExceptionInfo("Exception Occurs in follow-up action: " + e.getMessage(), e));
    }

0 votes


Accepted 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.

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)


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;

Ralph Schoon selected this answer as the correct answer

0 votes


One other answer

Permanent link

 I believe that https://rsjazz.wordpress.com/2016/02/04/setting-custom-attributes-for-scm-versionables/ shows the API involved.

0 votes

Comments

Thank you @Ralph Schoon for information but i just want to know, how i will get those custom attribute for server side. In the below uri its deal with client side
https://jazz.net/forum/questions/217952/how-to-retrieve-the-set-of-allowed-custom-scm-attributes-via-plain-java-client-api

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
× 169

Question asked: Aug 31 '18, 8:21 a.m.

Question was seen: 3,281 times

Last updated: Sep 04 '18, 12:12 p.m.

Confirmation Cancel Confirm