KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > util > ExportImportCommand


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.util;
22
23 /**
24  * @author tkavanagh
25  * @version $Id: ExportImportCommand.java 3970 2006-07-13 13:28:20Z swood $
26  */

27
28 import java.io.BufferedInputStream JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.FileNotFoundException JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Properties JavaDoc;
35
36 import com.jaspersoft.jasperserver.util.FileResourceBean;
37 import com.jaspersoft.jasperserver.api.common.domain.ExecutionContext;
38 import com.jaspersoft.jasperserver.api.common.domain.impl.ExecutionContextImpl;
39 import com.jaspersoft.jasperserver.api.engine.scheduling.service.ReportJobsPersistenceService;
40 import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;
41 import com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.persistent.CachedItem;
42 import com.jaspersoft.jasperserver.api.metadata.user.service.UserAuthorityService;
43
44 import org.springframework.context.support.ClassPathXmlApplicationContext;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48
49
50 public class ExportImportCommand {
51
52     private static final Log log = LogFactory.getLog(ExportImportCommand.class);
53
54     
55     private RepositoryService mRepo;
56     private UserAuthorityService mAuth;
57     private ReportJobsPersistenceService mSched;
58
59     private ExecutionContext mContext;
60     
61     private Properties JavaDoc mJdbcProps;
62
63     static boolean sImportOperation = false;
64     static boolean sExportOperation = false;
65     
66     private boolean mProcessUri = false;
67     private boolean mProcessUsers = false;
68     private boolean mProcessRoles = false;
69     private boolean mProcessJobReportUnits = false;
70     private boolean mProcessNothing = false;
71     
72     private boolean mUseNamedOutputDir = false; // used for both export and import
73
private boolean mUseNamedOutputFile = false; // used for both export and import
74
private String JavaDoc mOutputDirName;
75     private String JavaDoc mOutputFileName;
76     
77     private List JavaDoc mUriValuesList;
78     private List JavaDoc mUserNamesList;
79     private List JavaDoc mRoleNamesList;
80     private List JavaDoc mJobReportUnitsList;
81     private List JavaDoc mOutputFileNameList;
82     private List JavaDoc mOutputDirNameList;
83     
84     private boolean mImportProcessPrependPath = false;
85     private List JavaDoc mPrependPathValuesList;
86     
87     private boolean mVerbose = false;
88     private boolean mDevEnv = false;
89     
90     public static void main(String JavaDoc[] args) {
91         
92         System.out.println("ExportImportCommand: START");
93         
94         boolean result = true;
95         
96         ExportImportCommand command = new ExportImportCommand();
97         
98         if (args[0].equalsIgnoreCase("--export")) {
99             
100             sExportOperation = true;
101             
102             command.runExport(args);
103             
104         } else if (args[0].equalsIgnoreCase("--import")) {
105         
106             sImportOperation = true;
107             
108             result = command.runImport(args);
109             
110         } else {
111             System.out.println("\nExportImportCommand: unknown main process option, option=" + args[0]);
112         }
113         
114         if (result) {
115             System.out.println("ExportImportCommand: Successful");
116         } else {
117             System.out.println("ExportImportCommand: ERROR");
118             System.exit(1);
119         }
120     }
121     
122     public void runExport(String JavaDoc[] args) {
123         
124         String JavaDoc uriValue = null;
125         String JavaDoc[] userNames = null;
126         String JavaDoc[] roleNames = null;
127         String JavaDoc[] jobReportUnits = null;
128         
129         processCommandLineArgsExport(args);
130
131         setParameterValues();
132         
133         printoutOperationValues();
134         
135         setUpRepositoryConnections();
136         
137         if (!mProcessNothing) {
138         
139             if (mUriValuesList != null && mUriValuesList.size() > 0) {
140                 uriValue = (String JavaDoc) mUriValuesList.get(0);
141             }
142             
143             if (mUserNamesList != null && mUserNamesList.size() > 0) {
144                 userNames = (String JavaDoc[]) mUserNamesList.toArray(new String JavaDoc[mUserNamesList.size()]);
145             }
146             
147             if (mRoleNamesList != null && mRoleNamesList.size() > 0) {
148                 roleNames = (String JavaDoc[]) mRoleNamesList.toArray(new String JavaDoc[mRoleNamesList.size()]);
149             }
150             
151             if (mJobReportUnitsList != null && mJobReportUnitsList.size() > 0) {
152                 jobReportUnits = (String JavaDoc[]) mJobReportUnitsList.toArray(new String JavaDoc[mJobReportUnitsList.size()]);
153             }
154             
155             if (!mProcessNothing) {
156             
157                 ExportResource exporter = new ExportResource(mRepo,
158                         mAuth,
159                         mSched,
160                         mContext,
161                         uriValue,
162                         mProcessUsers,
163                         userNames,
164                         roleNames,
165                         mProcessJobReportUnits,
166                         jobReportUnits,
167                         mOutputDirName,
168                         mOutputFileName);
169                 
170                 exporter.process();
171             }
172         }
173     }
174
175     public boolean runImport(String JavaDoc[] args) {
176
177         String JavaDoc prependPath = null;
178         
179         processCommandLineArgsImport(args);
180         
181         setParameterValues();
182         
183         printoutOperationValues();
184
185         if (!mProcessNothing) {
186             
187             if (mPrependPathValuesList != null && mPrependPathValuesList.size() > 0) {
188                 
189                 String JavaDoc[] strArray =
190                     (String JavaDoc[]) mPrependPathValuesList.toArray(new String JavaDoc[mPrependPathValuesList.size()]);
191                 prependPath = strArray[0];
192             }
193             
194             setUpRepositoryConnections();
195             
196             ImportResource importer = new ImportResource(mRepo,
197                     mAuth,
198                     mSched,
199                     mContext,
200                     mOutputDirName,
201                     mOutputFileName,
202                     prependPath);
203             
204             return importer.process();
205         }
206         return false;
207     }
208     
209     protected void setParameterValues() {
210         
211         if (mUseNamedOutputDir) {
212         
213             if (mOutputDirNameList != null && mOutputDirNameList.size() > 0) {
214                 
215                 mOutputDirName = (String JavaDoc) mOutputDirNameList.get(0);
216                 
217             } else {
218                 System.out.println("ExportImportCommand: ERROR with output dir name");
219             }
220         } else {
221             
222             mOutputDirName = ExportResource.CATALOG_DIR_NAME;
223         }
224         
225         
226         if (mUseNamedOutputFile) {
227             
228             if (mOutputFileNameList != null && mOutputFileNameList.size() > 0) {
229             
230                 mOutputFileName = (String JavaDoc) mOutputFileNameList.get(0);
231             
232             } else {
233                 System.out.println("ExportImportCommand: ERROR with output file name");
234             }
235
236         } else {
237             
238             mOutputFileName = ExportResource.CATALOG_FILE_NAME;
239         }
240     }
241     
242     private void processCommandLineArgsExport(String JavaDoc[] args) {
243         
244         mUriValuesList = new ArrayList JavaDoc();
245         mUserNamesList = new ArrayList JavaDoc();
246         mRoleNamesList = new ArrayList JavaDoc();
247         mJobReportUnitsList = new ArrayList JavaDoc();
248         mOutputDirNameList = new ArrayList JavaDoc();
249         mOutputFileNameList = new ArrayList JavaDoc();
250         
251         
252         // TEMP
253
// System.out.println("ExportImportCommand: --- test: Print out all args");
254
// for (int i = 0; i < args.length; i++) {
255
// System.out.println("ExportImportCommand: ----- args[" + i + "]=" + args[i]);
256
// }
257

258         
259         if (args.length <= 1) {
260             System.out.println("\nError: No command line options found.\n");
261             printUsage();
262             System.exit(0);
263         }
264         
265         for (int i = 1; i < args.length; i++) { // NOTE: skip first arg (--export or --import)
266

267             if (args[i].startsWith("--uri")) {
268                 
269                 if (args[i].length() == "--uri".length()) {
270                 
271                     mProcessUri = true;
272                     
273                     for (int j = i + 1; j < args.length; j++) {
274                         
275                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
276                                                     
277                             mUriValuesList.add(args[j]);
278                             
279                         } else {
280                             if (j == i) {
281                                 System.out.println("--uri option does not include a value, args[j-" + j + "]=" + args[j]);
282                                 printUsage();
283                             } else {
284                                 break;
285                             }
286                         }
287                     }
288                 } else {
289                     int strLen = "--uri".length();
290                     if (args[i].length() > strLen) {
291                         mProcessUri = true;
292                         mUriValuesList.add(args[i].substring(strLen + 1));
293                     }
294                 }
295                     
296             } else if (args[i].startsWith("--users")) {
297                 
298                 if (args[i].length() == "--users".length()) {
299                     
300                     mProcessUsers = true;
301                     
302                     for (int j = i + 1; j < args.length; j++) {
303                         
304                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
305                             
306                             mUserNamesList.add(args[j]);
307                             System.out.println("username value=" + args[j]);
308                             
309                         } else {
310                             if (j == i) {
311                                 System.out.println("--users option does not include a value, args[j-" + j + "]=" + args[j]);
312                                 printUsage();
313                             } else {
314                                 break;
315                             }
316                         }
317                     }
318                 } else {
319                     int strLen = "--users".length();
320                     if (args[i].length() > strLen) {
321                         mProcessUsers = true;
322                         mUserNamesList.add(args[i].substring(strLen + 1));
323                         System.out.println("users value=" + args[i].substring(strLen + 1));
324                     }
325                 }
326
327             } else if (args[i].startsWith("--roles")) {
328                 
329                 if (args[i].length() == "--roles".length()) {
330                 
331                     mProcessRoles = true;
332                     
333                     for (int j = i + 1; j < args.length; j++) {
334                         
335                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
336                             
337                             mRoleNamesList.add(args[j]);
338                             System.out.println("rolename value=" + args[j]);
339                             
340                         } else {
341                             if (j == i) {
342                                 System.out.println("--roles option does not include a value, args[j-" + j + "]=" + args[j]);
343                                 printUsage();
344                             } else {
345                                 break;
346                             }
347                         }
348                     }
349                 } else {
350                     int strLen = "--roles".length();
351                     if (args[i].length() > strLen) {
352                         mProcessRoles = true;
353                         mRoleNamesList.add(args[i].substring(strLen + 1));
354                         System.out.println("roles value=" + args[i].substring(strLen + 1));
355                     }
356                 }
357                 
358             } else if (args[i].startsWith("--scheduled-jobs")) {
359                 
360                 if (args[i].length() == "--scheduled-jobs".length()) {
361                     
362                     mProcessJobReportUnits = true;
363                     
364                     for (int j = i + 1; j < args.length; j++) {
365                         
366                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
367                             
368                             mJobReportUnitsList.add(args[j]);
369                             System.out.println("job reportunit name value=" + args[j]);
370                             
371                         } else {
372                             if (j == i) {
373                                 System.out.println("--job-schedules option does not include a value, args[j-" + j + "]=" + args[j]);
374                                 printUsage();
375                             } else {
376                                 break;
377                             }
378                         }
379                     }
380                 } else {
381                     int strLen = "--scheduled-jobs".length();
382                     if (args[i].length() > strLen) {
383                         mProcessJobReportUnits = true;
384                         mJobReportUnitsList.add(args[i].substring(strLen + 1));
385                         System.out.println("scheduled jobs value=" + args[i].substring(strLen + 1));
386                     }
387                 }
388                 
389             } else if (args[i].startsWith("--export-file")) {
390                 
391                 if (args[i].length() == "--export-file".length()) {
392
393                     mUseNamedOutputFile = true;
394                     
395                     for (int j = i + 1; j < args.length; j++) {
396                         
397                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
398                             
399                             mOutputFileNameList.add(args[j]);
400                             System.out.println("export filename value=" + args[j]);
401                             
402                         } else {
403                             if (j == i) {
404                                 System.out.println("--export-filename option does not include a value, args[j-" + j + "]=" + args[j]);
405                                 printUsage();
406                             } else {
407                                 break;
408                             }
409                         }
410                     }
411                 } else {
412                     int strLen = "--export-file".length();
413                     if (args[i].length() > strLen) {
414                         mUseNamedOutputFile = true;
415                         mOutputFileNameList.add(args[i].substring(strLen + 1));
416                     }
417                 }
418                 
419             } else if (args[i].startsWith("--export-path")) {
420                 
421                 if (args[i].length() == "--export-path".length()) {
422                 
423                     mUseNamedOutputDir = true;
424                         
425                     for (int j = i + 1; j < args.length; j++) {
426                         
427                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
428                             
429                             mOutputDirNameList.add(args[j]);
430                             System.out.println("export dirname value=" + args[j]);
431                             
432                         } else {
433                             if (j == i) {
434                                 System.out.println("--export-directory option does not include a value, args[j-" + j + "]=" + args[j]);
435                                 printUsage();
436                             } else {
437                                 break;
438                             }
439                         }
440                     }
441                 } else {
442                     int strLen = "--export-path".length();
443                     if (args[i].length() > strLen) {
444                         mUseNamedOutputDir = true;
445                         mOutputDirNameList.add(args[i].substring(strLen + 1));
446                     }
447                 }
448
449             } else if (args[i].equalsIgnoreCase("--dev-env")) {
450                 
451                 mDevEnv = true;
452                 
453             } else if (args[i].equalsIgnoreCase("--verbose")) {
454                 
455                 mVerbose = true;
456                 
457             } else if (args[i].equalsIgnoreCase("--help")) {
458                 
459                 printUsage();
460                 System.exit(0);
461                 
462             } else {
463                 //System.out.println("ExportImportCommand: skipping option, option=" + args[i]);
464
//log.warn("ExportImportCommand: unknown command line option, option=" + args[i]);
465
//System.out.println("ExportImportCommand: unknown command line option, option=" + args[i]);
466
}
467         }
468         
469         // check for nothing to do
470
if (mProcessUri == false && mProcessUsers == false
471                 && mProcessRoles == false && mProcessJobReportUnits == false) {
472             
473             mProcessNothing = true;
474         }
475         
476     }
477
478     /*
479      * Note: this method has a work-around for command line options returned
480      * from a DOS batch file. --prepend-path=foobar arrives as
481      * args[0] = --prepend-path
482      * args[1] = foobar
483      *
484      * Under a linux script the same is:
485      * args[0] = --prepend-path=foobar
486      * todo: fix in DOS batch script and clean up code
487      */

488     private void processCommandLineArgsImport(String JavaDoc[] args) {
489         
490         mPrependPathValuesList = new ArrayList JavaDoc();
491         mOutputDirNameList = new ArrayList JavaDoc();
492         mOutputFileNameList = new ArrayList JavaDoc();
493         
494         // TEMP
495
System.out.println("ExportImportCommand: --- test: Print out all args");
496         for (int i = 0; i < args.length; i++) {
497             System.out.println("ExportImportCommand: ----- args[" + i + "]=" + args[i]);
498         }
499         
500         for (int i = 1; i < args.length; i++) { // NOTE: skip first arg (--export or --import)
501

502             if (args[i].startsWith("--prepend-path")) {
503                 
504                 // work-around for DOS batch file arg parsing - fix in batch file
505
// and clean up this code.
506
if (args[i].length() == "--prepend-path".length()) { // DOS breaks option into two bits
507

508                     mImportProcessPrependPath = true;
509                     
510                     for (int j = i + 1; j < args.length; j++) {
511                         
512                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
513                                                     
514                             mPrependPathValuesList.add(args[j]);
515                             System.out.println("prepend value=" + args[j]);
516                             
517                         } else {
518                             if (j == i) {
519                                 System.out.println("--prepend option does not include a value, args[j-" + j + "]=" + args[j]);
520                                 printUsage();
521                             } else {
522                                 break;
523                             }
524                         }
525                     }
526                 } else {
527                     // process from linux shell script
528
int strLen = "--prepend-path".length();
529                     if (args[i].length() > strLen) {
530                         mImportProcessPrependPath = true;
531                         mPrependPathValuesList.add(args[i].substring(strLen + 1));
532                     }
533                 }
534                 
535             } else if (args[i].startsWith("--import-file")) {
536                 
537                 if (args[i].length() == "--import-file".length()) {
538                     
539                     mUseNamedOutputFile = true;
540                     
541                     for (int j = i + 1; j < args.length; j++) {
542                         
543                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
544                             
545                             mOutputFileNameList.add(args[j]);
546                             System.out.println("import filename value=" + args[j]);
547                             
548                         } else {
549                             if (j == i) {
550                                 System.out.println("--import-filename option does not include a value, args[j-" + j + "]=" + args[j]);
551                                 printUsage();
552                             } else {
553                                 break;
554                             }
555                         }
556                     }
557                 } else {
558                     int strLen = "--import-file".length();
559                     if (args[i].length() > strLen) {
560                         mUseNamedOutputFile = true;
561                         mOutputFileNameList.add(args[i].substring(strLen + 1));
562                     }
563                 }
564                 
565             } else if (args[i].startsWith("--import-path")) {
566                 
567                 if (args[i].length() == "--import-path".length()) {
568                 
569                     mUseNamedOutputDir = true;
570                     
571                     for (int j = i + 1; j < args.length; j++) {
572                 
573                         if (args[j] != null && args[j].length() > 0 && !args[j].startsWith("-")) {
574                             
575                             mOutputDirNameList.add(args[j]);
576                             System.out.println("import dirname value=" + args[j]);
577                             
578                         } else {
579                             if (j == i) {
580                                 System.out.println("--import-directory option does not include a value, args[j-" + j + "]=" + args[j]);
581                                 printUsage();
582                             } else {
583                                 break;
584                             }
585                         }
586                     }
587                 } else {
588                     int strLen = "--import-path".length();
589                     if (args[i].length() > strLen) {
590                         mUseNamedOutputDir = true;
591                         mOutputDirNameList.add(args[i].substring(strLen + 1));
592                     }
593                 }
594                 
595             } else if (args[i].equalsIgnoreCase("--dev-env")) {
596                 
597                 mDevEnv = true;
598                 
599             } else if (args[i].equalsIgnoreCase("--verbose")) {
600                 
601                 mVerbose = true;
602                 
603             } else if (args[i].equalsIgnoreCase("--help")) {
604                 
605                 printUsage();
606                 System.exit(0);
607                 
608             } else {
609                 
610                 // todo: ### if the arg[] starts with "-" then we have an unrecognized arg, set doNothing and print usage
611

612             }
613         }
614     }
615
616     
617     public void printUsage() {
618         
619         if (sExportOperation) {
620                     
621             System.out.println("");
622             System.out.println("usage: ji-export [OPTIONS]");
623             
624             System.out.println("Specify repository resources such as reports, images, folders, users,");
625             System.out.println("roles, and scheduled jobs to export to an XML format file on disk.");
626             System.out.println("The export file is known as a \"repository catalog\" file.");
627             
628             System.out.println("");
629             System.out.println("Options:");
630             System.out.println(" --uri URI path of a repository resource");
631             System.out.println(" --users comma separated list of users to export");
632             System.out.println(" --roles comma separated list of roles to export");
633             System.out.println(" --scheduled-jobs comma separated list of scheduled jobs to export");
634             System.out.println(" (specify the URI path of the associated report)");
635             System.out.println(" --export-path path for export catalog file");
636             System.out.println(" --export-file name of export catalog file");
637             System.out.println(" --help print usage message");
638             System.out.println(" --verbose print flag settings used in the operation");
639             System.out.println("");
640             System.out.println("Examples:");
641             System.out.println(" ji-export --uri=/reports/samples/AllAccounts");
642             System.out.println(" ji-export --uri=/reports");
643             System.out.println(" ji-export --uri=/images/JRLogo --users=jasperadmin,joeuser");
644             System.out.println(" ji-export --roles=ROLE_USER,ROLE_ADMINISTRATOR");
645             System.out.println(" ji-export --uri=/images/JRLogo --export-path=myDir/myDir2 --export-file=myFileName");
646             System.out.println(" ji-export --scheduled-jobs=/reports/samples/AllAccounts");
647             System.out.println(" ji-export --uri=/images/JRLogo --users=jasperadmin,joeuser");
648             System.out.println(" ji-export --uri=/images/JRLogo --users=jasperadmin,joeuser");
649             System.out.println(" ji-export --uri=/images/JRLogo --users=jasperadmin,joeuser");
650             System.out.println("");
651             System.out.println("Notes:");
652             System.out.println(" The --uri option only allows for specifying one resource (ie a list of");
653             System.out.println(" resources is not currently supported). A URI can specify a resource such as");
654             System.out.println(" a ReportUnit. In this case, all associated resources such as images, ");
655             System.out.println(" sub-reports, datasources, resource bundles, and classfiles will be exported.");
656             System.out.println(" A URI can also specify a folder. If a folder is specified, the export operation");
657             System.out.println(" will export all files and folders contained in the folder. In addition, it will");
658             System.out.println(" recurse through all sub-folders.");
659             System.out.println("");
660             System.out.println(" If you export a user, the user information will be exported. In addition, the export");
661             System.out.println(" will keep information on roles that the user belongs to. On the import operation,");
662             System.out.println(" if the role names exist, the user will be added to these roles.");
663             System.out.println("");
664             System.out.println(" Special handling for roles: if you specify roles to export (and do not specify ");
665             System.out.println(" users to export), the associated users will also get exported. This is in order");
666             System.out.println(" to support the functionality where you, for instance, specify two roles ROLE_USER ");
667             System.out.println(" and ROLE_ADMINISTRATOR, and you would like all users who belong to these two roles to");
668             System.out.println(" also be exported. This is the current default behavior for roles.");
669             System.out.println(" Todo: enable this functionality with a --include-users-with-role option");
670             System.out.println("");
671             System.out.println(" If no catalog path or catalog file is specified, the default of ");
672             System.out.println(" target/ji-catalog/ji-catalog.xml will be used.");
673             System.out.println("");
674             System.out.println("");
675                         
676         } else if (sImportOperation) {
677
678             System.out.println("");
679             System.out.println("usage: ji-import [OPTIONS]");
680             
681             System.out.println("Read a repository catalog file from disk (created using the ji-export command) and ");
682             System.out.println("create the named resources in the current JapserIntelligence application repository.");
683             System.out.println("");
684             System.out.println("Options:");
685             System.out.println(" --prepend-path string to prepend to a URI path for all imported resources");
686             System.out.println(" --import-path path for import catalog file");
687             System.out.println(" --import-file name of import catalog file");
688             System.out.println(" --help print usage message");
689             System.out.println(" --verbose print flag settings used in the operation");
690             System.out.println("");
691             System.out.println("Examples:");
692             System.out.println(" ji-import");
693             System.out.println(" ji-import --import-path=myDir/myDir2 --import-file=myFileName");
694             System.out.println(" ji-import --prepend-path=myNewDir");
695             System.out.println("");
696             System.out.println("Notes:");
697             System.out.println(" The prepend-path option is handy for avoiding uri path conflicts on an import operation.");
698             System.out.println(" If the resource in the catalog file is \"/images/JRLogo\" and you set a prepend-path of \"myNewDir\"");
699             System.out.println(" then the resource will be imported and created under the URI path \"/myNewDir/images/JRLogo \".");
700             System.out.println(" So, if you are importing a set of resources into a repository and there is the possibility of");
701             System.out.println(" URI naming conflicts in the target repository, adding a prepend-path can help avoid these ");
702             System.out.println(" these naming conflicts.");
703             System.out.println("");
704             System.out.println(" On an import operation, if a resource is found in the target repository that has the same URI");
705             System.out.println(" as the resource that is attempting to be created, the create operation will be skipped and");
706             System.out.println(" the existing resource will be left unchanged (ie. an overwrite will not occur).");
707             System.out.println("");
708             System.out.println("");
709             
710             
711         } else {
712             System.out.println("ExportImportCommand: unknown usage");
713         }
714     }
715     
716     
717     
718     protected void printoutOperationValues() {
719         
720         if (mVerbose) {
721             if (sExportOperation) {
722                 System.out.println("");
723                 System.out.println("------ Export Operation Values: ");
724                 System.out.println(" --- mProcessUri=" + mProcessUri);
725                 System.out.println(" --- mProcessUsers=" + mProcessUsers);
726                 System.out.println(" --- mProcessRoles=" + mProcessRoles);
727                 System.out.println(" --- mProcessJobReportUnits=" + mProcessJobReportUnits);
728                 System.out.println(" --- mProcessNothing=" + mProcessNothing);
729                 System.out.println(" --- additional: mUseNamedOutputDir=" + mUseNamedOutputDir);
730                 System.out.println(" --- additional: mOutputDirName=" + mOutputDirName);
731                 System.out.println(" --- additional: mUseNamedOutputFile=" + mUseNamedOutputFile);
732                 System.out.println(" --- additional: mOutputFileName=" + mOutputFileName);
733                 System.out.println(" --- additional: mVerbose=" + mVerbose);
734                 System.out.println(" --- additional: mDevEnv=" + mDevEnv);
735                 System.out.println("");
736                 
737             } else if (sImportOperation) {
738                 System.out.println("");
739                 System.out.println("------ Import Operation Values: ");
740                 System.out.println(" --- mImportProcessPrependPath=" + mImportProcessPrependPath);
741                 System.out.println(" --- additional: mUseNamedOutputDir=" + mUseNamedOutputDir);
742                 System.out.println(" --- additional: mOutputDirName=" + mOutputDirName);
743                 System.out.println(" --- additional: mUseNamedOutputFile=" + mUseNamedOutputFile);
744                 System.out.println(" --- additional: mOutputFileName=" + mOutputFileName);
745                 System.out.println(" --- additional: mVerbose=" + mVerbose);
746                 System.out.println(" --- additional: mDevEnv=" + mDevEnv);
747                 System.out.println("");
748             } else {
749                 System.out.println("ERROR: unknown operation");
750             }
751         }
752     }
753     
754     protected void setUpRepositoryConnections() {
755         
756         ClassPathXmlApplicationContext appContext = null;
757         
758         try {
759             
760             if (mDevEnv) {
761                 
762                 System.out.println("ExportImportCommand: - running DEV Env mode");
763                 appContext =
764                     new ClassPathXmlApplicationContext(
765                             new String JavaDoc[] {"hibernateConfig.xml",
766                                 "viewService.xml",
767                                 "userAuthorityService.xml",
768                                 "engine.xml"});
769                 
770                 mRepo = (RepositoryService) appContext.getBean("repoService"); // bean name from dev
771

772             } else {
773                 
774                 System.out.println("ExportImportCommand: - running PROD Env mode");
775
776                 appContext =
777                     new ClassPathXmlApplicationContext(
778                             new String JavaDoc[] {"applicationContext-for-export.xml",
779                                 "applicationContext-report-scheduling-for-export.xml"});
780                 
781                 mRepo = (RepositoryService) appContext.getBean("repositoryService");
782             }
783             
784         
785         mAuth = (UserAuthorityService) appContext.getBean("userAuthorityService");
786         mSched = (ReportJobsPersistenceService) appContext.getBean("reportJobsPersistenceService");
787         
788         mSched = null;
789         
790         
791         this.mContext = new ExecutionContextImpl();
792         
793         } catch (Exception JavaDoc e) {
794             System.out.println("ExportImportCommand: caught exception, exception: " + e.getMessage());
795             e.printStackTrace();
796         }
797     }
798     
799     
800     protected void tearDown() {
801         
802         
803     }
804     
805 }
806
Popular Tags