Project

General

Profile

Revision 7a3e5df4

ID7a3e5df4ef6b9531bdc5686933ed400f87d53e6e
Parent 70cb2907
Child 3ab39923

Added by Andreas Kohlbecker over 2 years ago

ref #7269 redmine issues made private and public methods in interface

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/registration/messages/redmine/RedmineRegistrationMessageService.java
158 158
    public void postMessage(Registration registration, String message, User fromUser, User toUser)  throws ExternalServiceException {
159 159

  
160 160
        Issue issue = findIssue(registration);
161

  
161 162
        if(issue == null){
162 163
            issue = createIssue(registration);
163 164
        } else {
......
165 166
            issue.setPriorityId(getPreferenceAsInt(RedminePreferenceKey.ISSUE_PRIORITIY_ACTIVE_ID));
166 167
        }
167 168

  
168
        activateMessagesFor(registration, toUser);
169
        issue = activateIssueFor(registration, toUser);
169 170

  
170 171
        com.taskadapter.redmineapi.bean.User redmineFromUser = findUser(fromUser);
171 172
        if(redmineFromUser == null){
172 173
            redmineFromUser = createUser(fromUser);
173 174
        }
175

  
176
        // set issue public, otherwise adding a note on behalf of a contributor will fail
177
        issue.setPrivateIssue(false);
178
        try {
179
            redmineManager().getIssueManager().update(issue);
180
        } catch (RedmineException e) {
181
            throw new ExternalServiceException(getPreference(RedminePreferenceKey.REDMINE_URL), e);
182
        }
183

  
174 184
        issue.addWatchers(Arrays.asList(WatcherFactory.create(redmineFromUser.getId())));
175 185

  
176 186
        issue.setNotes(message);
......
184 194
            redmineManager().setOnBehalfOfUser(null);
185 195
        }
186 196

  
197
        // set issue private again
198
        issue.setNotes(null); // otherwise the note is added again
199
        issue.setPrivateIssue(true);
200
        try {
201
            redmineManager().getIssueManager().update(issue);
202
        } catch (RedmineException e) {
203
            throw new ExternalServiceException(getPreference(RedminePreferenceKey.REDMINE_URL), e);
204
        }
205

  
187 206

  
188 207
    }
189 208

  
......
442 461
    @Override
443 462
    public void activateMessagesFor(Registration registration, User user) throws ExternalServiceException {
444 463

  
464
        activateIssueFor(registration, user);
465

  
466
    }
467

  
468
    /**
469
     * @param registration
470
     * @param user
471
     * @throws ExternalServiceException
472
     */
473
    protected Issue activateIssueFor(Registration registration, User user) throws ExternalServiceException {
445 474
        com.taskadapter.redmineapi.bean.User redmineUser = findUser(user);
446 475
        if(redmineUser == null){
447 476
            redmineUser = createUser(user);
......
456 485
        } catch (RedmineException e) {
457 486
            throw new ExternalServiceException(getPreference(RedminePreferenceKey.REDMINE_URL), e);
458 487
        }
459

  
488
        return issue;
460 489
    }
461 490

  
462 491
    protected Issue createIssue(Registration registration) throws ExternalServiceException {
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/registration/messages/redmine/RedmineRegistrationMessageServiceTest.java
15 15

  
16 16
import java.io.FileNotFoundException;
17 17
import java.util.Arrays;
18
import java.util.HashMap;
18 19
import java.util.List;
20
import java.util.Map;
19 21

  
20 22
import org.junit.Before;
21 23
import org.junit.Test;
......
25 27

  
26 28
import com.taskadapter.redmineapi.RedmineException;
27 29
import com.taskadapter.redmineapi.bean.Issue;
30
import com.taskadapter.redmineapi.internal.ResultsWrapper;
28 31

  
32
import eu.etaxonomy.cdm.SpringProxyBeanHelper;
29 33
import eu.etaxonomy.cdm.api.service.INameService;
30 34
import eu.etaxonomy.cdm.api.service.IReferenceService;
31 35
import eu.etaxonomy.cdm.api.service.IRegistrationService;
32 36
import eu.etaxonomy.cdm.api.service.ITermService;
33 37
import eu.etaxonomy.cdm.api.service.IUserService;
34 38
import eu.etaxonomy.cdm.ext.common.ExternalServiceException;
39
import eu.etaxonomy.cdm.ext.registration.messages.IRegistrationMessageService;
35 40
import eu.etaxonomy.cdm.ext.registration.messages.Message;
36 41
import eu.etaxonomy.cdm.model.agent.Team;
37 42
import eu.etaxonomy.cdm.model.common.Extension;
......
78 83
    @SpringBeanByType
79 84
    INameService nameService;
80 85

  
81
    @SpringBeanByType
82 86
    private RedmineRegistrationMessageService messageService;
83 87

  
88
    @SpringBeanByType
89
    public void setIRegistrationMessageService(IRegistrationMessageService messageService) throws Exception {
90

  
91
        this.messageService = SpringProxyBeanHelper.getTargetObject(messageService, RedmineRegistrationMessageService.class);
92

  
93
    }
94

  
84 95

  
85 96
    private final String[] includeTableNames_create = new String[]{
86 97
            "TAXONNAME", "REFERENCE", "AGENTBASE", "HOMOTYPICALGROUP", "REGISTRATION",
......
97 108
                messageService.redmineManager().getUserManager().deleteUser(user.getId());
98 109
            }
99 110
        }
100
//                for(Object issue: messageService.redmineManager().getIssueManager().getIssues(null)){
101
//                    ...
102
//                }
111
        Map<String,String> params = new HashMap<>();
112
        params.put("offset", "0");
113
        params.put("limit", "100");
114
        params.put("status_id", "*"); // * to get open and closed issues
115
       while(true){
116
           ResultsWrapper<Issue> result = messageService.redmineManager().getIssueManager().getIssues(params);
117
           if(result.getResultsNumber() == 0){
118
               break;
119
           }
120
           for(Issue issue : result.getResults()){
121
               messageService.redmineManager().getIssueManager().deleteIssue(issue.getId());
122
           }
123
       }
103 124
    }
104 125

  
105 126
    @Test
......
109 130
        User submitter = (User) userService.loadUserByUsername(SUBMITTER);
110 131

  
111 132
        com.taskadapter.redmineapi.bean.User createdUser = null;
112
        try {
113
            createdUser = messageService.createUser(submitter);
114

  
115
            assertNotNull(createdUser);
116
            assertEquals(submitter.getUsername(), createdUser.getLogin());
117
            assertNotNull(createdUser.getId());
118

  
119
            User submitterReloaded = userService.load(submitter.getUuid(), Arrays.asList("person.extensions.$"));
120
            assertEquals(1, submitterReloaded.getPerson().getExtensions().size());
121
            Extension extension = submitterReloaded.getPerson().getExtensions().iterator().next();
122
            assertEquals(RedmineRegistrationMessageService.EXTTYPE_REGMESG_REDMINEUID_UUID, extension.getType().getUuid());
123
            assertEquals(createdUser.getId(), Integer.valueOf(extension.getValue()));
124

  
125
        } finally {
126
            if (createdUser != null) {
127
                messageService.redmineManager().getUserManager().deleteUser(createdUser.getId());
128
            }
129
            rollback();
130
        }
133

  
134
        createdUser = messageService.createUser(submitter);
135

  
136
        assertNotNull(createdUser);
137
        assertEquals(submitter.getUsername(), createdUser.getLogin());
138
        assertNotNull(createdUser.getId());
139

  
140
        User submitterReloaded = userService.load(submitter.getUuid(), Arrays.asList("person.extensions.$"));
141
        assertEquals(1, submitterReloaded.getPerson().getExtensions().size());
142
        Extension extension = submitterReloaded.getPerson().getExtensions().iterator().next();
143
        assertEquals(RedmineRegistrationMessageService.EXTTYPE_REGMESG_REDMINEUID_UUID, extension.getType().getUuid());
144
        assertEquals(createdUser.getId(), Integer.valueOf(extension.getValue()));
145

  
131 146
    }
132 147

  
133 148
    /**
......
146 161
        User submitter = (User) userService.loadUserByUsername(SUBMITTER);
147 162

  
148 163
        User curator = (User) userService.loadUserByUsername(CURATOR);
149
        try {
150 164

  
151
            if(!(submitter.getEmailAddress().equals(SUBMITTER + EMAIL_DOMAIN) &&  curator.getEmailAddress().equals(CURATOR + EMAIL_DOMAIN ))){
152
                throw new AssertionError("Email adresses must be '" + SUBMITTER + EMAIL_DOMAIN + "' and '" + CURATOR + EMAIL_DOMAIN + "',"
153
                        + " for futher information please refer to https://dev.e-taxonomy.eu/redmine/issues/7280");
154
            }
165
        if(!(submitter.getEmailAddress().equals(SUBMITTER + EMAIL_DOMAIN) &&  curator.getEmailAddress().equals(CURATOR + EMAIL_DOMAIN ))){
166
            throw new AssertionError("Email adresses must be '" + SUBMITTER + EMAIL_DOMAIN + "' and '" + CURATOR + EMAIL_DOMAIN + "',"
167
                    + " for futher information please refer to https://dev.e-taxonomy.eu/redmine/issues/7280");
168
        }
155 169

  
156 170

  
157
            Registration reg = registrationService.load(REGISTRATION_ID, Arrays.asList("$"));
158
            issue = messageService.createIssue(reg);
159
            reg.setStatus(RegistrationStatus.READY);
160
            messageService.updateIssueStatus(reg);
161
            issue = messageService.findIssue(reg);
162
            assertEquals("ready", issue.getStatusName());
163
        } finally {
164
            if (issue != null) {
165
                try {
166
                    messageService.redmineManager().getIssueManager().deleteIssue(issue.getId());
167
                } catch (Exception e) { /* IGNORE*/ }
168
            }
169
            try {
170
                com.taskadapter.redmineapi.bean.User redmineSubmitter = messageService.findUser(submitter);
171
                messageService.redmineManager().getUserManager().deleteUser(redmineSubmitter.getId());
171
        Registration reg = registrationService.load(REGISTRATION_ID, Arrays.asList("$"));
172
        issue = messageService.createIssue(reg);
173
        reg.setStatus(RegistrationStatus.READY);
174
        messageService.updateIssueStatus(reg);
175
        issue = messageService.findIssue(reg);
176
        assertEquals("ready", issue.getStatusName());
172 177

  
173
            } catch (Exception e) { /* IGNORE*/ }
174
        }
175 178

  
176 179
    }
177 180

  
......
192 195
        com.taskadapter.redmineapi.bean.User redmineCurator = null;
193 196
        com.taskadapter.redmineapi.bean.User redmineSubmitter = null;
194 197

  
195
        try {
196
            assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
197
            assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
198

  
199
            // post a message, this will create an issue and will add a comment
200
            String messageText1 = "hey submitter how is life in a test environment?";
201
            messageService.postMessage(reg, messageText1, curator, submitter);
202
            issue = messageService.findIssue(reg);
203
            assertTrue(issue.isPrivateIssue());
204
            redmineCurator = messageService.findUser(curator);
205
            redmineSubmitter = messageService.findUser(submitter);
206
            assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
207

  
208
            assertEquals(1, messageService.countActiveMessagesFor(reg, submitter));
209

  
210
            // 2. post a message back to curator
211
            String messageText2 = "pretty boring in here. It is horrible. If you know a way out of here, please help!";
212
            messageService.postMessage(reg, messageText2, submitter, curator);
213
            issue = messageService.findIssue(reg);
214
            assertEquals(redmineCurator.getId(), issue.getAssigneeId());
215
            assertEquals(1, messageService.countActiveMessagesFor(reg, curator));
216
            assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
217

  
218
            // 3. post a message back submitter
219
            String messageText3 = "Dear Submitter, the only solution it to end this test, hold on, just a millisec ...";
220
            messageService.postMessage(reg, messageText3, curator, submitter);
221
            issue = messageService.findIssue(reg);
222
            assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
223
            assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
224
            assertEquals(2, messageService.countActiveMessagesFor(reg, submitter));
225

  
226
            // 4. inactivate messages
227
            messageService.inactivateMessages(reg);
228
            issue = messageService.findIssue(reg);
229
            assertNull(issue.getAssigneeName());
230
            assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
231
            assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
232

  
233
            List<Message> messages = messageService.listMessages(reg);
234
            assertEquals(3, messages.size());
235

  
236
            // 5. registration becomes rejected
237
            reg.setStatus(RegistrationStatus.REJECTED);
238
            messageService.updateIssueStatus(reg);
239
            issue = messageService.findIssue(reg);
240
            assertEquals("rejected", issue.getStatusName());
241

  
242
            // 6. check all the messages in this issue
243
            assertEquals(messageText1, messages.get(0).getText());
244
            assertEquals(curator, messages.get(0).getFrom());
245

  
246
            assertEquals(messageText2, messages.get(1).getText());
247
            assertEquals(submitter, messages.get(1).getFrom());
248

  
249
            assertEquals(messageText3, messages.get(2).getText());
250
            assertEquals(curator, messages.get(2).getFrom());
251

  
252
        } finally {
253
            try {
254
                if (issue != null) {
255
                    messageService.redmineManager().getIssueManager().deleteIssue(issue.getId());
256
                }
257
                if(redmineCurator != null){
258
                    messageService.redmineManager().getUserManager().deleteUser(redmineCurator.getId());
259
                } else {
260
                    redmineCurator = messageService.findUser(curator);
261
                    messageService.redmineManager().getUserManager().deleteUser(redmineCurator.getId());
262
                }
263
                if(redmineSubmitter != null){
264
                    messageService.redmineManager().getUserManager().deleteUser(redmineSubmitter.getId());
265
                } else {
266
                    redmineSubmitter = messageService.findUser(submitter);
267
                    messageService.redmineManager().getUserManager().deleteUser(redmineSubmitter.getId());
268
                }
269
            } catch (Exception e) { /* IGNORE*/ }
270
        }
198

  
199
        assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
200
        assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
201

  
202
        // post a message, this will create an issue and will add a comment
203
        String messageText1 = "hey submitter how is life in a test environment?";
204
        messageService.postMessage(reg, messageText1, curator, submitter);
205
        issue = messageService.findIssue(reg);
206
        assertTrue(issue.isPrivateIssue());
207
        redmineCurator = messageService.findUser(curator);
208
        redmineSubmitter = messageService.findUser(submitter);
209
        assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
210

  
211
        assertEquals(1, messageService.countActiveMessagesFor(reg, submitter));
212

  
213
        // 2. post a message back to curator
214
        String messageText2 = "pretty boring in here. It is horrible. If you know a way out of here, please help!";
215
        messageService.postMessage(reg, messageText2, submitter, curator);
216
        issue = messageService.findIssue(reg);
217
        assertEquals(redmineCurator.getId(), issue.getAssigneeId());
218
        assertEquals(1, messageService.countActiveMessagesFor(reg, curator));
219
        assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
220

  
221
        // 3. post a message back submitter
222
        String messageText3 = "Dear Submitter, the only solution it to end this test, hold on, just a millisec ...";
223
        messageService.postMessage(reg, messageText3, curator, submitter);
224
        issue = messageService.findIssue(reg);
225
        assertEquals(redmineSubmitter.getId(), issue.getAssigneeId());
226
        assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
227
        assertEquals(2, messageService.countActiveMessagesFor(reg, submitter));
228

  
229
        // 4. inactivate messages
230
        messageService.inactivateMessages(reg);
231
        issue = messageService.findIssue(reg);
232
        assertNull(issue.getAssigneeName());
233
        assertEquals(0, messageService.countActiveMessagesFor(reg, curator));
234
        assertEquals(0, messageService.countActiveMessagesFor(reg, submitter));
235

  
236
        List<Message> messages = messageService.listMessages(reg);
237
        assertEquals(3, messages.size());
238

  
239
        // 5. registration becomes rejected
240
        reg.setStatus(RegistrationStatus.REJECTED);
241
        messageService.updateIssueStatus(reg);
242
        issue = messageService.findIssue(reg);
243
        assertEquals("rejected", issue.getStatusName());
244

  
245
        // 6. check all the messages in this issue
246
        assertEquals(messageText1, messages.get(0).getText());
247
        assertEquals(curator, messages.get(0).getFrom());
248

  
249
        assertEquals(messageText2, messages.get(1).getText());
250
        assertEquals(submitter, messages.get(1).getFrom());
251

  
252
        assertEquals(messageText3, messages.get(2).getText());
253
        assertEquals(curator, messages.get(2).getFrom());
254

  
255

  
271 256
    }
272 257

  
273 258

  
cdmlib-test/src/main/java/eu/etaxonomy/cdm/SpringProxyBeanHelper.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm;
10

  
11
import org.springframework.aop.framework.Advised;
12
import org.springframework.aop.support.AopUtils;
13

  
14
/**
15
 * @author a.kohlbecker
16
 * @since Feb 23, 2018
17
 *
18
 */
19
public class SpringProxyBeanHelper {
20

  
21

  
22
    @SuppressWarnings({"unchecked"})
23
    public static <T> T getTargetObject(Object proxy, Class<T> targetClass) throws Exception {
24
      if (AopUtils.isJdkDynamicProxy(proxy)) {
25
        return (T) ((Advised)proxy).getTargetSource().getTarget();
26
      } else {
27
        return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
28
      }
29
    }
30
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)