It's all about the answers!

Ask a question

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


Raj Kumar (21216) | asked Aug 31 '18, 8:21 a.m.
edited Sep 04 '18, 12:12 p.m. by David Lafreniere (4.8k7)

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));
    }

Accepted answer


permanent link
David Lafreniere (4.8k7) | answered Sep 04 '18, 9:51 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Sep 04 '18, 10:08 a.m.
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

One other answer



permanent link
Ralph Schoon (63.1k33645) | answered Sep 01 '18, 2:13 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Comments
Raj Kumar commented Sep 03 '18, 7:42 a.m.

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