88import java .text .SimpleDateFormat ;
99import java .util .ArrayList ;
1010import java .util .Date ;
11+ import java .util .HashMap ;
1112import java .util .HashSet ;
1213import java .util .List ;
14+ import java .util .Map ;
1315import java .util .Set ;
1416
1517import javax .annotation .PostConstruct ;
3032import com .topcoder .clients .dao .ClientDAO ;
3133import com .topcoder .clients .dao .ProjectDAO ;
3234import com .topcoder .clients .model .Client ;
35+ import com .topcoder .service .project .entities .DirectProjectType ;
3336import com .topcoder .service .project .entities .ProjectAnswer ;
37+ import com .topcoder .service .project .entities .ProjectAnswerOption ;
3438import com .topcoder .service .project .entities .ProjectAudit ;
3539import com .topcoder .service .project .entities .ProjectQuestion ;
40+ import com .topcoder .service .project .entities .ProjectQuestionOption ;
3641import com .topcoder .security .RolePrincipal ;
3742import com .topcoder .security .TCSubject ;
3843import com .topcoder .security .auth .module .UserProfilePrincipal ;
@@ -2112,7 +2117,7 @@ private boolean isAdminRole(TCSubject tcSubject) {
21122117 *
21132118 * @since 1.1
21142119 */
2115- private ProjectData copyProjectData (ProjectData project ) {
2120+ private static ProjectData copyProjectData (ProjectData project ) {
21162121 ProjectData projectData = new ProjectData ();
21172122
21182123 projectData .setName (project .getName ());
@@ -2126,14 +2131,135 @@ private ProjectData copyProjectData(ProjectData project) {
21262131 projectData .setCompletionDate (project .getCompletionDate ());
21272132 projectData .setProjectType (project .getProjectType ());
21282133 projectData .setProjectCategory (project .getProjectCategory ());
2129- projectData .setProjectAnswers (project .getProjectAnswers ());
2134+
2135+ if (project .getProjectAnswers () != null & !project .getProjectAnswers ().isEmpty ()) {
2136+ List <ProjectAnswer > answers = new ArrayList <ProjectAnswer >();
2137+ for (ProjectAnswer answer : project .getProjectAnswers ()) {
2138+ answers .add (copyProjectAnswer (answer ));
2139+ }
2140+ projectData .setProjectAnswers (answers );
2141+ }
21302142
21312143 projectData .setFixedBugContestFee (project .getFixedBugContestFee ());
21322144 projectData .setPercentageBugContestFee (project .getPercentageBugContestFee ());
21332145
21342146 return projectData ;
21352147 }
2148+
2149+ /**
2150+ * Copy the project answer
2151+ *
2152+ * @param answer the project answer to copy
2153+ * @return the copied project answer
2154+ */
2155+ private static ProjectAnswer copyProjectAnswer (ProjectAnswer answer ) {
2156+ ProjectAnswer copy = new ProjectAnswer ();
2157+ copy .setId (answer .getId ());
2158+
2159+ if (answer .getMultipleAnswers () != null && !answer .getMultipleAnswers ().isEmpty ()) {
2160+ copy .setMultipleAnswers (new ArrayList <String >(answer .getMultipleAnswers ()));
2161+ }
2162+
2163+ Map <Long , ProjectQuestionOption > questionOptionMap = new HashMap <Long , ProjectQuestionOption >();
2164+
2165+ if (answer .getProjectQuestion () != null ) {
2166+ copy .setProjectQuestion (copyProjectQuestion (answer .getProjectQuestion ()));
2167+
2168+ List <ProjectQuestionOption > questionOptions = copy .getProjectQuestion ().getQuestionOptions ();
2169+ if (questionOptions != null ) {
2170+ for (ProjectQuestionOption option : questionOptions ) {
2171+ questionOptionMap .put (option .getId (), option );
2172+ }
2173+ }
2174+ }
2175+
2176+ if (answer .getOptionAnswers () != null && !answer .getOptionAnswers ().isEmpty ()) {
2177+ List <ProjectAnswerOption > options = new ArrayList <ProjectAnswerOption >();
2178+ for (ProjectAnswerOption option : answer .getOptionAnswers ()) {
2179+ options .add (copyProjectAnswerOption (option , questionOptionMap ));
2180+ }
2181+ copy .setOptionAnswers (options );
2182+ }
2183+
2184+ copy .setTextualAnswer (answer .getTextualAnswer ());
2185+
2186+ return copy ;
2187+ }
2188+
2189+ /**
2190+ * Copy the project question
2191+ *
2192+ * @param question the project question to copy
2193+ * @return the copied project question
2194+ */
2195+ private static ProjectQuestion copyProjectQuestion (ProjectQuestion question ) {
2196+ ProjectQuestion copy = new ProjectQuestion ();
2197+ copy .setAnswerHtmlId (question .getAnswerHtmlId ());
2198+ copy .setId (question .getId ());
2199+ copy .setMultipleAnswersHtmlXpath (question .getMultipleAnswersHtmlXpath ());
2200+
2201+ if (question .getQuestionOptions () != null && !question .getQuestionOptions ().isEmpty ()) {
2202+ List <ProjectQuestionOption > options = new ArrayList <ProjectQuestionOption >();
2203+ for (ProjectQuestionOption option : question .getQuestionOptions ()) {
2204+ options .add (copyProjectQuestionOption (option ));
2205+ }
2206+ copy .setQuestionOptions (options );
2207+ }
2208+ if (question .getDirectProjectType () != null ) {
2209+ DirectProjectType projectType = new DirectProjectType ();
2210+ projectType .setId (question .getDirectProjectType ().getId ());
2211+ projectType .setName (question .getDirectProjectType ().getName ());
2212+ copy .setDirectProjectType (projectType );
2213+ }
21362214
2215+ copy .setQuestionText (question .getQuestionText ());
2216+
2217+ return copy ;
2218+ }
2219+
2220+ /**
2221+ * Copy the project question option.
2222+ *
2223+ * @param option the project question option
2224+ * @return the copied the project question option
2225+ */
2226+ private static ProjectQuestionOption copyProjectQuestionOption (ProjectQuestionOption option ) {
2227+ ProjectQuestionOption copy = new ProjectQuestionOption ();
2228+
2229+ copy .setAnswerHtmlId (option .getAnswerHtmlId ());
2230+ copy .setAssociatedTextboxHtmlId (option .getAssociatedTextboxHtmlId ());
2231+ copy .setHasAssociatedTextbox (option .isHasAssociatedTextbox ());
2232+ copy .setId (option .getId ());
2233+ copy .setQuestionOptionText (option .getQuestionOptionText ());
2234+
2235+ return copy ;
2236+ }
2237+
2238+ /**
2239+ * Copy the project answer option.
2240+ *
2241+ * @param option the project answer option
2242+ * @param questionOptions the question options
2243+ * @return the copied project answer option
2244+ */
2245+ private static ProjectAnswerOption copyProjectAnswerOption (ProjectAnswerOption option ,
2246+ Map <Long , ProjectQuestionOption > questionOptions ) {
2247+ ProjectAnswerOption copy = new ProjectAnswerOption ();
2248+
2249+ copy .setAnswerHtmlValue (option .getAnswerHtmlValue ());
2250+ copy .setId (option .getId ());
2251+
2252+ if (option .getProjectQuestionOption () != null ) {
2253+ ProjectQuestionOption questionOption = questionOptions .get (option .getProjectQuestionOption ().getId ());
2254+ if (questionOption == null ) {
2255+ questionOption = copyProjectQuestionOption (option .getProjectQuestionOption ());
2256+ }
2257+ copy .setProjectQuestionOption (questionOption );
2258+ }
2259+
2260+ return copy ;
2261+ }
2262+
21372263 /**
21382264 * <p>
21392265 * Logs the entrance of a method.
0 commit comments