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; }
private static String storeTag(UCMEntity entity, String cgi) throws TagException { logger.fine(entity.getFullyQualifiedName()); String cmd = "mkhlink -ttext \"" + cgi + "\" " + __TAG_NAME + " " + entity; CmdResult res = null; try { res = Cleartool.run(cmd); } catch (AbnormalProcessTerminationException e) { logger.warning("Unable add tag: " + e.getMessage()); Matcher match = pattern_hlink_type_missing.matcher(e.getMessage()); if (match.find()) { logger.fine("Found match"); // 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, cgi, __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 { // throw new UCMException( e ); throw new TagException(entity, cgi, __TAG_NAME, Type.CREATION_FAILED, e); } } String tag = res.stdoutBuffer.toString(); Matcher match = pattern_remove_verbose_tag.matcher(tag); if (!match.find()) { // throw new UCMException( "Could not create tag", UCMType.TAG_CREATION_FAILED ); throw new TagException(entity, cgi, __TAG_NAME, Type.CREATION_FAILED); } return match.group(1); }