static String getJiraHomeValue(InputStream propertiesInputStream) throws ParseException, IOException { Properties applicationProperties = new Properties(); applicationProperties.load(propertiesInputStream); String jiraHome = applicationProperties.getProperty("jira.home"); if (jiraHome == null) { // We didn't find the jira.home property :( throw new ParseException("Unable to find the jira.home property."); } return jiraHome; }
private void handleApplicationUser(final Map<String,String> attributes) throws ParseException { final String id = attributes.get(ID); if (StringUtils.isEmpty(id)) { throw new ParseException("Missing 'id' field for ApplicationUser entry."); } final String userKey = attributes.get(USER_KEY); if (StringUtils.isEmpty(userKey)) { throw new ParseException("Missing userKey from ApplicationUser id = " + id); } final String lowerUserName = attributes.get(LOWER_USER_NAME); if (StringUtils.isEmpty(lowerUserName)) { throw new ParseException("Missing lowerUserName from ApplicationUser id = " + id); } appUserIdToUserKeyMap.put(id, userKey); userNameToUserKeyMap.put(lowerUserName, userKey); }
protected String removeProtocolPrefix(final String jdbcUrl) throws ParseException { String protocolPrefix = getProtocolPrefix(); if (!jdbcUrl.startsWith(protocolPrefix)) { throw new ParseException("Unable to parse the JDBC URL '" + jdbcUrl + "'. It should start with protocol prefix '" + protocolPrefix + "'."); } // Strip off the protocol prefix return jdbcUrl.substring(protocolPrefix.length()); }
public void handleEntity(final String entityName, final Map<String, String> attributes) throws ParseException { // Check if the incoming entity is one of the ones we are interested in. if (entityTypeName.equals(entityName)) { final String id = (String) attributes.get("id"); final String name = (String) attributes.get("name"); if (StringUtils.isBlank(id)) { throw new ParseException("Encountered an entity of type '" + entityTypeName + "' with a missing ID."); } if (StringUtils.isBlank(name)) { throw new ParseException("The name of " + entityTypeName + " '" + id + "' is missing."); } mapperEntityRegister.registerOldValue(id, name); } }
private <T> T verifyRequiredAttribute(final Map<String, String> attributes, final String key, Function<String, T> transform) throws ParseException { String id = attributes.get(EntityProperty.ID); id = id == null ? "" : " '" + id + "'"; if (!attributes.containsKey(key)) { throw new ParseException("The " + key + " of " + EntityProperty.ENTITY_NAME + id + " is missing "); } try { return transform.get(attributes.get(key)); } catch (NumberFormatException e) { throw new ParseException("The " + key + " of " + EntityProperty.ENTITY_NAME + id + " has invalid value " + attributes.get(key)); } catch (IllegalArgumentException e) { throw new ParseException("The " + key + " of " + EntityProperty.ENTITY_NAME + id + " has invalid value " + attributes.get(key)); } } }
public void handleEntity(final String entityName, final Map<String, String> attributes) throws ParseException { // Check if the incoming entity is one of the ones we are interested in. if (ISSUETYPE_ENTITY_NAME.equals(entityName)) { final String id = (String) attributes.get("id"); final String name = (String) attributes.get("name"); final String style = (String) attributes.get("style"); if (StringUtils.isBlank(id)) { throw new ParseException("Encountered an entity of type '" + ISSUETYPE_ENTITY_NAME + "' with a missing ID."); } if (StringUtils.isBlank(name)) { throw new ParseException("The name of " + ISSUETYPE_ENTITY_NAME + " '" + id + "' is missing."); } // Keep track if our issue type is a subtask or not issueTypeMapper.registerOldValue(id, name, JIRA_SUBTASK.equals(style)); } }
public ExternalCustomField parseCustomField(final Map attributes) throws ParseException { if (attributes == null) { throw new IllegalArgumentException("The 'attributes' parameter cannot be null."); } // <CustomField id="10001" customfieldtypekey="com.atlassian.jira.plugin.system.customfieldtypes:textarea" // customfieldsearcherkey="com.atlassian.jira.plugin.system.customfieldtypes:textsearcher" name="text cf"/> final String id = (String) attributes.get("id"); final String name = (String) attributes.get("name"); final String customfieldtypekey = (String) attributes.get("customfieldtypekey"); // Validate the data if (StringUtils.isEmpty(id)) { throw new ParseException("No 'id' field for CustomField."); } if (StringUtils.isEmpty(name)) { throw new ParseException("No 'name' field for CustomField " + id + "."); } if (StringUtils.isEmpty(customfieldtypekey)) { throw new ParseException("No 'customfieldtypekey' field for CustomField " + id + "."); } return new ExternalCustomField(id, name, customfieldtypekey); }
public BackupOverviewBuilderImpl.FieldConfigSchemeIssueType parseFieldConfigSchemeIssueType(final Map attributes) throws ParseException { if (attributes == null) { throw new IllegalArgumentException("The 'attributes' parameter cannot be null."); } // <FieldConfigSchemeIssueType id="10012" issuetype="1" fieldconfigscheme="10011" fieldconfiguration="10011"/> final String id = (String) attributes.get("id"); if (StringUtils.isEmpty(id)) { throw new ParseException("No 'id' field for FieldConfigSchemeIssueType."); } final String fieldconfigscheme = (String) attributes.get("fieldconfigscheme"); if (StringUtils.isEmpty(fieldconfigscheme)) { throw new ParseException("No 'fieldconfigscheme' field for FieldConfigSchemeIssueType."); } // Issue type can be null and this represents a configuration for all issue types final String issuetype = (String) attributes.get("issuetype"); return new BackupOverviewBuilderImpl.FieldConfigSchemeIssueType(fieldconfigscheme, issuetype); } }
private static Node getOnlyChildNode(final Node parentNode, final String tagName) throws ParseException { List<Node> childNodes = getChildNodes(parentNode, tagName); if (childNodes.size() == 1) { return childNodes.get(0); } else if (childNodes.size() == 0) { return null; } else { throw new ParseException("Expected to find one child <" + tagName + "> in <" + parentNode.getNodeName() + "> but found " + childNodes.size()); } }
public ExternalChangeItem parse(final Map attributes) throws ParseException { Null.not("attributes", attributes); //<ChangeItem id="10014" group="10006" fieldtype="jira" field="security" oldvalue="10000" oldstring="level1" newvalue="10001" newstring="level2"/> final String id = (String) attributes.get(ID); final String changeGroupId = (String) attributes.get(GROUP); final String fieldType = (String) attributes.get(FIELD_TYPE); final String field = (String) attributes.get(FIELD); final String oldvalue = (String) attributes.get(OLD_VALUE); final String oldstring = (String) attributes.get(OLD_STRING); final String newvalue = (String) attributes.get(NEW_VALUE); final String newstring = (String) attributes.get(NEW_STRING); if (StringUtils.isEmpty(id)) { throw new ParseException("A change item must have an id specified."); } if (StringUtils.isEmpty(changeGroupId)) { throw new ParseException("Change item '" + id + "' is missing the change group id."); } if (StringUtils.isEmpty(field)) { throw new ParseException("Change item '" + id + "' is missing the 'field' attribute."); } return new ExternalChangeItem(id, changeGroupId, fieldType, field, oldvalue, oldstring, newvalue, newstring); }
public ExternalGroup parse(final Map attributes) throws ParseException { Null.not("attributes", attributes); // The XML entry for Groups looks like: // <OSGroup id="10011" name="Dudettes"/> // We ignore the ID as this is only for internal use of Open Symphony, and is never exposed to JIRA. final String name = (String) attributes.get(GROUP_NAME); if (StringUtils.isEmpty(name)) { throw new ParseException("A Group in the backup file is missing the groupName parameter."); } return new ExternalGroup(name); } }
private void handleChangeGroup(final String entityName, final Map<String, String> attributes) throws ParseException { // keep the change group id's so we can correctly store the changeItems if (ChangeGroupParser.CHANGE_GROUP_ENTITY_NAME.equals(entityName)) { final ExternalChangeGroup externalChangeGroup = getChangeGroupParser().parse(attributes); final String idStr = externalChangeGroup.getId(); if (idStr != null) { try { final Long id = new Long(idStr); changeGroupIds.add(id); } catch (final NumberFormatException e) { throw new ParseException("Unable to parse the id for changeGroup '" + idStr + "'"); } } else { throw new ParseException("Encountered a ChangeGroup entry without an id, this should not happen."); } } }
public ExternalWatcher parseWatcher(final Map attributes) throws ParseException { Null.not("attributes", attributes); // <UserAssociation sourceName="admin" sinkNodeId="10000" sinkNodeEntity="Issue" associationType="WatchIssue"/> final String sinkNodeEntity = (String) attributes.get(SINK_NODE_ENTITY); final String associationType = (String) attributes.get(ASSOCIATION_TYPE); // We only handle watchers if the type is correct and the association is for an issue if (!IssueParser.ISSUE_ENTITY_NAME.equals(sinkNodeEntity) || !ASSOCIATION_TYPE_WATCH_ISSUE.equals(associationType)) { return null; } final String issueId = (String) attributes.get(SINK_NODE_ID); final String watcher = (String) attributes.get(SOURCE_NAME); if (StringUtils.isBlank(issueId)) { throw new ParseException("A watcher must have an associated issue id."); } if (StringUtils.isBlank(watcher)) { throw new ParseException("Watcher associated with issue id '" + issueId + "' has no user associated with the watch."); } final ExternalWatcher externalWatcher = new ExternalWatcher(); externalWatcher.setIssueId(issueId); externalWatcher.setWatcher(watcher); return externalWatcher; } }
public ExternalVoter parseVoter(final Map attributes) throws ParseException { Null.not("attributes", attributes); // <UserAssociation sourceName="admin" sinkNodeId="10000" sinkNodeEntity="Issue" associationType="VoteIssue"/> final String sinkNodeEntity = (String) attributes.get(SINK_NODE_ENTITY); final String associationType = (String) attributes.get(ASSOCIATION_TYPE); // We only handle voters if the type is correct and the association is for an issue if (!IssueParser.ISSUE_ENTITY_NAME.equals(sinkNodeEntity) || !ASSOCIATION_TYPE_VOTE_ISSUE.equals(associationType)) { return null; } final String issueId = (String) attributes.get(SINK_NODE_ID); final String voter = (String) attributes.get(SOURCE_NAME); if (StringUtils.isBlank(issueId)) { throw new ParseException("A voter must have an associated issue id."); } if (StringUtils.isBlank(voter)) { throw new ParseException("Voter associated with issue id '" + issueId + "' has no user associated with the vote."); } final ExternalVoter externalVoter = new ExternalVoter(); externalVoter.setIssueId(issueId); externalVoter.setVoter(voter); return externalVoter; }
throw new ParseException("No 'id' field for IssueLinkType."); throw new ParseException("No 'linkname' field for IssueLinkType " + id + ".");
CustomField getCustomField(final ExternalCustomFieldValue externalCustomFieldValue) throws ParseException { // Find the custom field this value is mapped to final String oldCustomFieldId = externalCustomFieldValue.getCustomFieldId(); final String mappedId = projectImportMapper.getCustomFieldMapper().getMappedId(oldCustomFieldId); if (mappedId == null) { log.error("During custom field value validation we have encountered a custom field with id '" + oldCustomFieldId + "' which the mapper does not know about."); throw new ParseException( "During custom field value validation we have encountered a custom field with id '" + oldCustomFieldId + "' which the mapper does not know about."); } final Long customFieldId; try { customFieldId = new Long(mappedId); } catch (final NumberFormatException e) { log.error("Encountered a custom field value with a custom field id '" + mappedId + "' which is not a valid number."); throw new ParseException("Encountered a custom field value with a custom field id '" + mappedId + "' which is not a valid number."); } return customFieldManager.getCustomFieldObject(customFieldId); }
private boolean handleChangeItem(final Map<String, String> attributes) throws ParseException { final ExternalChangeItem externalChangeItem = getChangeItemParser().parse(attributes); try { final Long groupId = new Long(externalChangeItem.getChangeGroupId()); return changeGroupIds.contains(groupId); } catch (final NumberFormatException e) { throw new ParseException("Unable to parse the changeGroup id'" + externalChangeItem.getChangeGroupId() + "' for change item."); } }
public ExternalChangeGroup parse(final Map attributes) throws ParseException { Null.not("attributes", attributes); // <ChangeGroup id="10020" issue="10000" author="admin" created="2008-01-22 11:04:10.339"/> final String id = (String) attributes.get(ID); final String issueId = (String) attributes.get(ISSUE); if (StringUtils.isEmpty(id)) { throw new ParseException("A change group must have an id specified."); } if (StringUtils.isEmpty(issueId)) { throw new ParseException("A change group must have an issue id specified."); } final String created = (String) attributes.get(CREATED); final String author = (String) attributes.get(AUTHOR); final ExternalChangeGroup changeGroup = new ExternalChangeGroup(); changeGroup.setId(id); changeGroup.setIssueId(issueId); changeGroup.setAuthor(author); if (created != null) { changeGroup.setCreated(java.sql.Timestamp.valueOf(created)); } return changeGroup; }
private void writeXmlText(final String entityName, final Map<String, String> attributes, final ModelEntity modelEntity) throws ParseException { if (!entityName.equals(currentEntity)) { endDocument(); } if (printWriter == null) { try { currentEntity = entityName; printWriter = projectImportTemporaryFiles.getWriter(entityName); } catch (IOException e) { throw new ParseException(e.getMessage()); } } // Create a GenericEntity final GenericEntity genericEntity = new GenericEntity(delegator, modelEntity, attributes); genericEntity.writeXmlText(printWriter, null); }
private void writeXmlText(final String entityName, final Map<String, String> attributes, final ModelEntity modelEntity) throws ParseException { if (!entityName.equals(currentEntity)) { endDocument(); } if (printWriter == null) { try { currentEntity = entityName; printWriter = projectImportTemporaryFiles.getWriter(entityName); } catch (IOException e) { throw new ParseException(e.getMessage()); } } // Create a GenericEntity final GenericEntity genericEntity = new GenericEntity(delegator, modelEntity, attributes); genericEntity.writeXmlText(printWriter, null); }