1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.impex.schema.execute;
17
18 import java.io.File;
19
20 import org.kuali.common.impex.model.Schema;
21 import org.kuali.common.impex.model.util.ModelUtils;
22 import org.kuali.common.impex.schema.DefaultDumpSchemaService;
23 import org.kuali.common.impex.schema.DumpSchemaService;
24 import org.kuali.common.util.Assert;
25 import org.kuali.common.util.FileSystemUtils;
26 import org.kuali.common.util.Project;
27 import org.kuali.common.util.ProjectUtils;
28 import org.kuali.common.util.StringFilter;
29 import org.kuali.common.util.execute.Executable;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class ProjectSchemaExportExecutable implements Executable {
34
35 private static final Logger logger = LoggerFactory.getLogger(ProjectSchemaExportExecutable.class);
36
37 public static final boolean DEFAULT_EXECUTION_SKIP = false;
38 public static final DumpSchemaService DEFAULT_EXPORT_SCHEMA_SERVICE = new DefaultDumpSchemaService();
39 public static final String DEFAULT_SCHEMA_FILENAME = "schema.xml";
40
41 boolean skip = DEFAULT_EXECUTION_SKIP;
42 DumpSchemaService service = DEFAULT_EXPORT_SCHEMA_SERVICE;
43 String schemaFilename = DEFAULT_SCHEMA_FILENAME;
44
45 Project project;
46 Schema schema;
47 StringFilter nameFilter;
48 File stagingDir;
49 File basedir;
50
51 @Override
52 public void execute() {
53
54
55 if (skip) {
56 return;
57 }
58
59
60 Assert.notNull(service, "service is null");
61 Assert.notNull(schema, "schema is null");
62 Assert.notNull(project, "project is null");
63 Assert.notNull(stagingDir, "stagingDir is null");
64 Assert.notNull(basedir, "basedir is null");
65
66
67 Schema clone = new Schema(schema);
68
69
70 ModelUtils.filter(clone, nameFilter);
71
72
73 File schemaFile = ProjectUtils.getResourceFile(stagingDir, project, schemaFilename);
74
75
76 logger.info("Creating - [{}]", FileSystemUtils.getRelativePathQuietly(basedir, schemaFile));
77
78
79 service.dumpSchema(clone, schemaFile);
80
81 }
82
83 public boolean isSkip() {
84 return skip;
85 }
86
87 public void setSkip(boolean skip) {
88 this.skip = skip;
89 }
90
91 public DumpSchemaService getService() {
92 return service;
93 }
94
95 public void setService(DumpSchemaService service) {
96 this.service = service;
97 }
98
99 public StringFilter getNameFilter() {
100 return nameFilter;
101 }
102
103 public void setNameFilter(StringFilter nameFilter) {
104 this.nameFilter = nameFilter;
105 }
106
107 public Project getProject() {
108 return project;
109 }
110
111 public void setProject(Project project) {
112 this.project = project;
113 }
114
115 public Schema getSchema() {
116 return schema;
117 }
118
119 public void setSchema(Schema schema) {
120 this.schema = schema;
121 }
122
123 public File getStagingDir() {
124 return stagingDir;
125 }
126
127 public void setStagingDir(File stagingDir) {
128 this.stagingDir = stagingDir;
129 }
130
131 public File getBasedir() {
132 return basedir;
133 }
134
135 public void setBasedir(File basedir) {
136 this.basedir = basedir;
137 }
138
139 }