Skip to content

Commit 170e87c

Browse files
author
Vladimir Kotal
committed
use annotation to generate DTO
1 parent c7e42fc commit 170e87c

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3636
import org.opengrok.indexer.logger.LoggerFactory;
3737
import org.opengrok.indexer.util.ClassUtil;
38+
import org.opengrok.indexer.util.DTOElement;
3839
import org.opengrok.indexer.util.PathUtils;
3940

4041
/**
@@ -55,18 +56,26 @@ public class RepositoryInfo implements Serializable {
5556

5657
private static final long serialVersionUID = 3L;
5758

59+
@DTOElement
5860
private String directoryNameRelative;
5961
private transient String directoryNameCanonical;
6062

63+
@DTOElement
6164
protected Boolean working;
65+
@DTOElement
6266
protected String type; // type of the repository, should be unique
67+
@DTOElement
6368
protected boolean remote;
6469
protected String[] datePatterns = new String[0];
70+
@DTOElement
6571
protected String parent;
72+
@DTOElement
6673
protected String branch;
74+
@DTOElement
6775
protected String currentVersion;
68-
76+
@DTOElement
6977
private boolean handleRenamedFiles;
78+
@DTOElement
7079
private boolean historyEnabled;
7180

7281
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
24+
package org.opengrok.indexer.util;
25+
26+
import java.lang.annotation.ElementType;
27+
import java.lang.annotation.Retention;
28+
import java.lang.annotation.RetentionPolicy;
29+
import java.lang.annotation.Target;
30+
31+
@Retention(RetentionPolicy.RUNTIME)
32+
@Target(ElementType.FIELD)
33+
public @interface DTOElement {
34+
String key() default "";
35+
}

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2828
import org.opengrok.indexer.history.RepositoryInfo;
2929
import org.opengrok.indexer.util.ClassUtil;
30+
import org.opengrok.indexer.util.DTOElement;
3031

3132
import javax.ws.rs.GET;
3233
import javax.ws.rs.Path;
@@ -44,22 +45,13 @@ public class RepositoriesController {
4445

4546
private RuntimeEnvironment env = RuntimeEnvironment.getInstance();
4647

47-
static class RepositoryInfoDTO {
48-
// Contains all members of RepositoryInfo except datePatterns
49-
String directoryNameRelative;
50-
Boolean working;
51-
String type;
52-
boolean remote;
53-
String parent;
54-
String branch;
55-
String currentVersion;
56-
}
57-
5848
private Object createRepositoryInfoTO(RepositoryInfo ri) {
5949
// ModelMapper assumes getters/setters so use BeanGenerator to provide them.
6050
BeanGenerator beanGenerator = new BeanGenerator();
61-
for (Field field : RepositoryInfoDTO.class.getDeclaredFields()) {
62-
beanGenerator.addProperty(field.getName(), field.getType());
51+
for (Field field : RepositoryInfo.class.getDeclaredFields()) {
52+
if (field.isAnnotationPresent(DTOElement.class)) {
53+
beanGenerator.addProperty(field.getName(), field.getType());
54+
}
6355
}
6456
Object bean = beanGenerator.create();
6557

0 commit comments

Comments
 (0)