Skip to content

Commit 7345e85

Browse files
author
Vladimir Kotal
committed
use DTO to access RepositoryInfo data
1 parent e03dc42 commit 7345e85

File tree

2 files changed

+118
-4
lines changed

2 files changed

+118
-4
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,92 @@ public class RepositoryInfo implements Serializable {
6868
private boolean handleRenamedFiles;
6969
private boolean historyEnabled;
7070

71+
public static class RepositoryInfoTO implements Serializable {
72+
private static final long serialVersionUID = -1;
73+
74+
// same members as in RepositoryInfo except datePatterns
75+
private String directoryNameRelative;
76+
private boolean working;
77+
private String type;
78+
private boolean remote;
79+
private String parent;
80+
private String branch;
81+
private String currentVersion;
82+
private boolean handleRenamedFiles;
83+
private boolean historyEnabled;
84+
85+
public String getDirectoryNameRelative() {
86+
return directoryNameRelative;
87+
}
88+
89+
public void setDirectoryNameRelative(String directoryNameRelative) {
90+
this.directoryNameRelative = directoryNameRelative;
91+
}
92+
93+
public boolean isWorking() {
94+
return working;
95+
}
96+
97+
public void setWorking(boolean working) {
98+
this.working = working;
99+
}
100+
101+
public String getType() {
102+
return type;
103+
}
104+
105+
public void setType(String type) {
106+
this.type = type;
107+
}
108+
109+
public boolean isRemote() {
110+
return remote;
111+
}
112+
113+
public void setRemote(boolean remote) {
114+
this.remote = remote;
115+
}
116+
117+
public String getParent() {
118+
return parent;
119+
}
120+
121+
public void setParent(String parent) {
122+
this.parent = parent;
123+
}
124+
125+
public String getBranch() {
126+
return branch;
127+
}
128+
129+
public void setBranch(String branch) {
130+
this.branch = branch;
131+
}
132+
133+
public String getCurrentVersion() {
134+
return currentVersion;
135+
}
136+
137+
public void setCurrentVersion(String currentVersion) {
138+
this.currentVersion = currentVersion;
139+
}
140+
141+
public boolean isHandleRenamedFiles() {
142+
return handleRenamedFiles;
143+
}
144+
145+
public void setHandleRenamedFiles(boolean handleRenamedFiles) {
146+
this.handleRenamedFiles = handleRenamedFiles;
147+
}
148+
149+
public boolean isHistoryEnabled() {
150+
return historyEnabled;
151+
}
152+
153+
public void setHistoryEnabled(boolean historyEnabled) {
154+
this.historyEnabled = historyEnabled;
155+
}
156+
}
71157

72158
/**
73159
* Empty constructor to support serialization.
@@ -87,6 +173,34 @@ public RepositoryInfo(RepositoryInfo orig) {
87173
this.currentVersion = orig.currentVersion;
88174
}
89175

176+
/**
177+
* @return Data Transfer Object for RepositoryInfo
178+
*/
179+
public RepositoryInfoTO getRepositoryInfoData() {
180+
return createRepositoryInfoTO();
181+
}
182+
183+
private RepositoryInfoTO createRepositoryInfoTO() {
184+
RepositoryInfoTO ri = new RepositoryInfoTO();
185+
186+
if (this.working == null) {
187+
ri.working = false;
188+
} else {
189+
ri.working = this.working;
190+
}
191+
192+
ri.directoryNameRelative = this.directoryNameRelative;
193+
ri.type = this.type;
194+
ri.remote = this.remote;
195+
ri.parent = this.parent;
196+
ri.branch = this.branch;
197+
ri.currentVersion = this.currentVersion;
198+
ri.handleRenamedFiles = this.handleRenamedFiles;
199+
ri.historyEnabled = this.historyEnabled;
200+
201+
return ri;
202+
}
203+
90204
/**
91205
* @return true if the repository handles renamed files, false otherwise.
92206
*/
@@ -193,7 +307,7 @@ public boolean isWorking() {
193307
*
194308
* @param working is repository working
195309
*/
196-
public void setWorking(boolean working) {
310+
public void setWorking(Boolean working) {
197311
this.working = working;
198312
}
199313

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/RepositoriesController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public class RepositoriesController {
4141

4242
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
4343

44-
private RepositoryInfo getRepositoryInfo(String repositoryPath) {
44+
private RepositoryInfo.RepositoryInfoTO getRepositoryInfoData(String repositoryPath) {
4545
for (RepositoryInfo ri : env.getRepositories()) {
4646
if (ri.getDirectoryNameRelative().equals(repositoryPath)) {
47-
return ri;
47+
return ri.getRepositoryInfoData();
4848
}
4949
}
5050

@@ -57,7 +57,7 @@ private RepositoryInfo getRepositoryInfo(String repositoryPath) {
5757
public Object get(@QueryParam("repository") final String repositoryPath, @PathParam("field") final String field)
5858
throws IOException {
5959

60-
RepositoryInfo ri = getRepositoryInfo(repositoryPath);
60+
RepositoryInfo.RepositoryInfoTO ri = getRepositoryInfoData(repositoryPath);
6161
if (ri == null) {
6262
throw new WebApplicationException("cannot find repository with path: " + repositoryPath,
6363
Response.Status.NOT_FOUND);

0 commit comments

Comments
 (0)