示例#1
0
文件: Tag.java 项目: wolfgarnet/cool
  private static Tag newTag(String tagType, String tagID, UCMEntity entity, String cgi)
      throws TagException, UnableToCreateEntityException, UCMEntityNotFoundException,
          UnableToGetEntityException, UnableToInitializeEntityException {
    logger.fine("ENTITY=" + entity.toString());
    logger.fine("CGI FOR NEW = " + cgi);
    // System.out.println( "CGI==="+cgi );

    /* Delete any existing Tags with the unique ID */
    logger.fine(
        "Deleting Tags with ID: "
            + tagType
            + tagID
            + " for entity "
            + entity.getFullyQualifiedName());
    deleteTagsWithID(tagType, tagID, entity);

    cgi = "tagtype=" + tagType + "&tagid=" + tagID + (cgi.length() > 0 ? "&" + cgi : "");
    String fqname = storeTag(entity, cgi);

    Tag tag = (Tag) UCMEntity.getEntity(Tag.class, fqname);
    // tag.SetEntry( "tagtype", tagType );
    // tag.SetEntry( "tagid", tagID );
    tag.setKeyValue(cgi);
    tag.setTagEntity(entity);

    return tag;
  }
示例#2
0
文件: Tag.java 项目: wolfgarnet/cool
  public static Tag getTag(UCMEntity entity, String tagType, String tagID, boolean create)
      throws TagException, UnableToInitializeEntityException, UnableToCreateEntityException,
          UCMEntityNotFoundException, UnableToGetEntityException {
    logger.fine(entity.toString());
    List<Tag> tags = getTags(entity);

    for (Tag t : tags) {
      logger.fine("Current: " + t);
      /* Is it the correct tag? Return it! */
      if (t.getTagType().equals(tagType) && t.getTagID().equals(tagID)) {
        logger.fine("This is it!");
        t.setTagEntity(entity);
        return t;
      }
    }

    logger.fine("Could not find the Tag with ID " + tagType + tagID + ". Creating new.");

    if (create) {
      return newTag(entity, tagType, tagID);
    } else {
      return null;
    }
  }
示例#3
0
文件: Tag.java 项目: wolfgarnet/cool
  public static List<Tag> getTags(UCMEntity entity)
      throws TagException, UnableToInitializeEntityException {
    logger.fine(entity.toString());

    String cmd = "describe -ahlink " + __TAG_NAME + " -l " + entity;
    CmdResult res = null;
    try {
      res = Cleartool.run(cmd);
    } catch (AbnormalProcessTerminationException e) {
      Matcher match = pattern_hlink_type_missing.matcher(e.getMessage());
      logger.warning("Unable to get tags: " + e.getMessage());
      if (match.find()) {
        logger.fine("Tag type not found");
        // UCM.addMessage( "The Hyperlink type \"" + match.group( 1 ) + "\" was not
        // found.\nInstallation: \"cleartool mkhltype " + __TAG_NAME + " -c \"Hyperlink type for
        // tagging entities\"\"" );
        // throw new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) + "\" was not
        // found. ", e.getMessage(), UCMType.UNKNOWN_HLINK_TYPE );
        // UCMException ucme = new UCMException( "ClearCase hyperlink type \"" + match.group( 1 ) +
        // "\" was not found. ", e, UCMType.UNKNOWN_HLINK_TYPE );
        // ucme.addInformation(  "The Hyperlink type \"" + match.group( 1 ) + "\" was not
        // found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging
        // entities\" " + __TAG_NAME + "@" + match.group( 2 ) );
        TagException te = new TagException(entity, "", __TAG_NAME, Type.NO_SUCH_HYPERLINK, e);
        te.addInformation(
            "The Hyperlink type \""
                + match.group(1)
                + "\" was not found.\nInstallation: \"cleartool mkhltype -global -c \"Hyperlink type for tagging entities\" "
                + __TAG_NAME
                + "@"
                + match.group(2));
        throw te;
      } else {
        logger.fine("Something else");
        throw new TagException(entity, "", __TAG_NAME, Type.CREATION_FAILED, e);
      }
    }

    List<String> list = res.stdoutList;

    // List<Tuple<String, String>> tags = new ArrayList<Tuple<String,
    // String>>();
    // List<String[]> tags = new ArrayList<String[]>();

    ArrayList<Tag> tags = new ArrayList<Tag>();

    /* There are tags */
    if (list.size() > 2) {
      for (int i = 2; i < list.size(); i++) {
        logger.fine("[" + i + "]" + list.get(i));

        Matcher match = pattern_tags.matcher(list.get(i));
        if (match.find()) {
          // tags.add( new Tuple<String, String>( match.group( 1 ),
          // match.group( 2 ) ) );
          // tags.add( new String[] { match.group( 1 ), match.group( 2 ) } );

          Tag tag = (Tag) UCMEntity.getEntity(Tag.class, match.group(1).trim());
          tag.setKeyValue(match.group(2));
          tags.add(tag);
        }
      }
    }

    return tags;
  }