public MessageSet validateBackupProjectImportableSystemLevel( final JiraServiceContext jiraServiceContext, final BackupProject backupProject, final BackupSystemInformation backupSystemInformation) { validateJiraServiceContext(jiraServiceContext); // No need to check if backupProject has null members, we will never create backup project like // that. Null.not("backupSystemInformation", backupSystemInformation); final MessageSet messageSet = new MessageSetImpl(); final I18nHelper i18n = jiraServiceContext.getI18nBean(); // Need to provide a backupProject if (backupProject == null) { messageSet.addErrorMessage(getText(i18n, "admin.error.project.import.null.project")); jiraServiceContext .getErrorCollection() .addErrorMessage(getText(i18n, "admin.error.project.import.null.project")); return messageSet; } // The user must have the system administrator permission to perform a project import if (!userHasSysAdminPermission(jiraServiceContext.getUser())) { messageSet.addErrorMessage(getText(i18n, "admin.errors.project.import.must.be.admin")); } else { // Verify that if the backup projects custom field plugins exist that they are of the right // version in this JIRA instance // NOTE: warnings, such as the plugin not existing or the custom field being not importable or // out of context // are not checked here, that is handled by the next phase of the import. validateCustomFieldPluginVersions( backupProject, backupSystemInformation.getPluginVersions(), messageSet, i18n); final String projectKey = backupProject.getProject().getKey(); final Project existingProject = projectManager.getProjectObjByKey(projectKey); if (existingProject == null) { // It does not really make sense to warn that we will create a project for them if there are // already errors. if (!messageSet.hasAnyErrors()) { messageSet.addWarningMessage( getText(i18n, "admin.warning.project.import.no.existing.project", projectKey)); } } else { // We need to make sure that the project does not contain issues, versions, components, // etc... validateExistingProjectHasValidStateForImport( backupProject, backupSystemInformation, existingProject, i18n, messageSet); } } // Copy the errors into the service context error collection jiraServiceContext.getErrorCollection().addErrorMessages(messageSet.getErrorMessages()); return messageSet; }
private boolean projectHasDefaultAssigneeUnassigned( final BackupProject backupProject, final BackupSystemInformation backupSystemInformation) { Long assigneeType; try { assigneeType = new Long(backupProject.getProject().getAssigneeType()); } catch (final NumberFormatException e) { // Act as null - best guess assigneeType = null; } if (assigneeType == null) { // Then it was dependant on the value of the "Allow unassigned issues" setting. return backupSystemInformation.unassignedIssuesAllowed(); } return assigneeType.longValue() == AssigneeTypes.UNASSIGNED; }
public ProjectImportData getProjectImportData( final JiraServiceContext jiraServiceContext, final ProjectImportOptions projectImportOptions, final BackupProject backupProject, final BackupSystemInformation backupSystemInformation, final TaskProgressInterval taskProgressInterval) { Null.not("backupProject", backupProject); Null.not("projectImportOptions", projectImportOptions); Null.not("backupSystemInformation", backupSystemInformation); validateJiraServiceContext(jiraServiceContext); // The user must have the system administrator permission to perform a project import if (!userHasSysAdminPermission(jiraServiceContext.getUser())) { jiraServiceContext .getErrorCollection() .addErrorMessage( getText( jiraServiceContext.getI18nBean(), "admin.errors.project.import.must.be.admin")); return null; } final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); final I18nHelper i18n = jiraServiceContext.getI18nBean(); final ProjectImportData projectImportData; try { // First step is to go through the import file again, populating our mappers and creating // partitioned XML files. // Create the Task Progress Processor for this subtask. EntityCountTaskProgressProcessor taskProgressProcessor = null; if (taskProgressInterval != null) { taskProgressProcessor = new EntityCountTaskProgressProcessor( taskProgressInterval, i18n.getText( "admin.message.project.import.manager.do.mapping.extracting.project.data"), backupSystemInformation.getEntityCount(), i18n); } projectImportData = projectImportManager.getProjectImportData( projectImportOptions, backupProject, backupSystemInformation, taskProgressProcessor); } catch (final IOException e) { log.error( "There was a problem accessing the file '" + projectImportOptions.getPathToBackupXml() + "' when performing a project import.", e); errorCollection.addErrorMessage( getText( i18n, "admin.errors.project.import.problem.reading.backup", projectImportOptions.getPathToBackupXml())); return null; } catch (final SAXException e) { log.error( "There was a problem with the SAX parsing of the file '" + projectImportOptions.getPathToBackupXml() + "' when performing a project import."); errorCollection.addErrorMessage( getText( i18n, "admin.errors.project.import.sax.problem", projectImportOptions.getPathToBackupXml(), e.getMessage())); return null; } return projectImportData; }