Exemple #1
0
  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;
  }
Exemple #2
0
  private static Tag newTag(UCMEntity entity, String tagType, String tagID)
      throws UnableToInitializeEntityException {
    Tag tag = (Tag) UCMEntity.getEntity(Tag.class, "tag@0@" + entity.getPVob().getName());
    // tag.SetEntry( "tagtype", tagType );
    // tag.SetEntry( "tagid", tagID );
    String cgi = "tagtype=" + tagType + "&tagid=" + tagID;
    tag.setKeyValue(cgi);
    tag.setTagEntity(entity);

    tag.setCreated(true);

    return tag;
  }
Exemple #3
0
  public void setKeyValue(String cgi) {
    keyval = Tag.CGIToHash(cgi);
    this.tagType = (keyval.containsKey("tagtype") ? keyval.get("tagtype") : "");
    this.tagID = (keyval.containsKey("tagid") ? keyval.get("tagid") : "");

    this.loaded = true;
  }
Exemple #4
0
  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;
    }
  }
Exemple #5
0
  public static Tag persist(Tag tag)
      throws TagException, UnableToCreateEntityException, UnableToLoadEntityException,
          UCMEntityNotFoundException, UnableToGetEntityException,
          UnableToInitializeEntityException {
    /* Make the new tag */
    Tag newtag =
        Tag.newTag(
            tag.getTagType(),
            tag.getTagID(),
            tag.getTagEntity(),
            Tag.mapToCGI(tag.GetEntries(), true));

    /* Delete the old tag */
    delete(tag);

    return newtag;
  }
Exemple #6
0
  private static void deleteTagsWithID(String tagType, String tagID, UCMEntity entity)
      throws TagException, UnableToInitializeEntityException {
    logger.fine(tagType + tagID);

    List<Tag> list = getTags(entity);
    logger.fine(list.size() + " Tags!");

    for (Tag t : list) {
      logger.fine("Testing " + t.getTagType() + " > " + t.getTagID());

      if (t.getTagID().matches("^.*tagtype=" + tagType + ".*$")
          && t.getTagID().matches("^.*tagid=" + tagID + ".*$")) {
        String cmd = "rmhlink " + t.getTagType();
        try {
          Cleartool.run(cmd);
        } catch (AbnormalProcessTerminationException e) {
          // throw new UCMException( "Unable to delete tag with " + tagID + ": " + e.getMessage() );
          throw new TagException(entity, "", __TAG_NAME, Type.DELETION_FAILED, e);
        }
      }
    }
  }
Exemple #7
0
  public static void run(String[] args)
      throws UnableToCreateEntityException, UnableToLoadEntityException, UCMEntityNotFoundException,
          UnknownEntityException, TagException, UnableToGetEntityException,
          UnableToInitializeEntityException {
    Options o = new Options();

    Option oentity = new Option("entity", "e", true, 1, "The UCM entity");
    Option otag = new Option("tag", "t", true, 1, "The tag. Given as: \"key1=val1&key2=val2\"");
    Option otagtype = new Option("tagtype", "y", true, 1, "The tag type");
    Option otagid = new Option("tagid", "i", true, 1, "The tag id");

    o.setOption(oentity);
    o.setOption(otag);
    o.setOption(otagtype);
    o.setOption(otagid);

    o.setDefaultOptions();

    o.setHeader("Set a tag for an UCM entity");
    o.setSyntax("SetTag -e <entity> -t <tag> -y <tag type> -i <tag id>");
    o.setDescription(
        "Examples:"
            + Options.linesep
            + "SetTag -e baseline:bls@\\somevob -T \"key1=val1&key2=val2\" -y myjob -i 10101"
            + Options.linesep
            + "SetTag -e baseline:bls@\\somevob -T \"key1=&key2=val2\" -y myjob -i 10101"
            + Options.linesep
            + "The last example will remove key1 from the tag");

    o.parse(args);

    try {
      o.checkOptions();
    } catch (Exception e) {
      logger.severe("Incorrect option: " + e.getMessage());
      o.display();
      System.exit(1);
    }

    UCMEntity e = null;

    e = UCMEntity.getEntity(oentity.getString()).load();

    Tag tag = e.getTag(otagtype.getString(), otagid.getString());

    /* Split key value structure */
    String[] tags = otag.getString().split("&");

    for (String t : tags) {

      String[] entry = t.split("=");

      try {
        logger.config("+(" + entry[0] + ", " + entry[1] + ") ");

        tag.setEntry(entry[0].trim(), entry[1].trim());
      } catch (ArrayIndexOutOfBoundsException ea) {
        logger.info("-(" + entry[0] + ") ");
        tag.removeEntry(entry[0]);
      }
    }

    try {
      tag.persist();
    } catch (TagException ex) {
      if (ex.getType().equals(Type.CREATION_FAILED)) {
        logger.severe("Could not persist the tag.");
        System.exit(1);
      }
    }

    if (tag.isCreated()) {
      logger.info("Tag created.");
    } else {
      logger.info("Tag updated.");
    }
  }
Exemple #8
0
  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;
  }