Skip to content

Commit c5dc55b

Browse files
Use openbis 20.10.x (#510)
* wip * testable version * cleanuop * adapt to new openbis instance and model * remove workarounds, fix issues * fix small issues * rename experiment * remove unused impot * use autoclosable sessions * address review * remove todo
1 parent 2f19768 commit c5dc55b

File tree

8 files changed

+331
-301
lines changed

8 files changed

+331
-301
lines changed

project-management-infrastructure/pom.xml

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@
3535
<dependency>
3636
<groupId>life.qbic</groupId>
3737
<artifactId>openbis-api</artifactId>
38-
<version>19.06.5</version>
39-
<scope>compile</scope>
40-
</dependency>
41-
<dependency>
42-
<groupId>life.qbic</groupId>
43-
<artifactId>openbis-client-lib</artifactId>
44-
<version>1.6.0</version>
38+
<version>20.10.7.3</version>
39+
<classifier>r1700646105</classifier>
4540
<scope>compile</scope>
4641
</dependency>
4742
<dependency>

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/QbicSampleDataRepo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface QbicSampleDataRepo {
3535
*/
3636
void deleteAll(ProjectCode projectCode, Collection<SampleCode> samples);
3737

38-
void updateAll(Collection<Sample> samples);
38+
void updateAll(Project project, Collection<Sample> samples);
3939

4040
boolean canDeleteSample(ProjectCode projectCode, SampleCode sampleCode);
4141
}

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/SampleRepositoryImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public List<Sample> findSamplesByBatchId(
131131
public void updateAll(Project project,
132132
Collection<Sample> updatedSamples) {
133133
qbicSampleRepository.saveAll(updatedSamples);
134-
sampleDataRepo.updateAll(updatedSamples);
134+
sampleDataRepo.updateAll(project, updatedSamples);
135135
}
136136

137137
@Override

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/openbis/AnalyteTermMapper.java

-25
This file was deleted.

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/openbis/OpenbisConnector.java

+165-191
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package life.qbic.projectmanagement.infrastructure.sample.openbis;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static org.slf4j.LoggerFactory.getLogger;
5+
6+
import ch.ethz.sis.openbis.generic.asapi.v3.IApplicationServerApi;
7+
import ch.ethz.sis.openbis.generic.dssapi.v3.IDataStoreServerApi;
8+
import ch.systemsx.cisd.common.spring.HttpInvokerUtils;
9+
import ch.systemsx.cisd.common.exceptions.UserFailureException;
10+
import org.slf4j.Logger;
11+
12+
/**
13+
*
14+
* <b>Handles openBIS login and session</b>
15+
*
16+
* @since 1.0.0
17+
*/
18+
public class OpenbisSessionFactory {
19+
20+
private final String applicationServerUrl;
21+
private final String userName;
22+
private final String password;
23+
24+
public OpenbisSessionFactory(String applicationServerUrl, String userName, String password) {
25+
this.applicationServerUrl = applicationServerUrl;
26+
this.userName = userName;
27+
this.password = password;
28+
}
29+
30+
public OpenBisSession getSession() {
31+
return new AutoCloseableOpenBisSession(userName, password, applicationServerUrl);
32+
}
33+
public OpenBisSession getSession(String token) {
34+
return new TokenBaseOpenBisSession(token, applicationServerUrl);
35+
}
36+
37+
public static class OpenBisSessionException extends RuntimeException {
38+
39+
public OpenBisSessionException() {
40+
}
41+
42+
public OpenBisSessionException(String message) {
43+
super(message);
44+
}
45+
46+
public OpenBisSessionException(String message, Throwable cause) {
47+
super(message, cause);
48+
}
49+
50+
public OpenBisSessionException(Throwable cause) {
51+
super(cause);
52+
}
53+
54+
public OpenBisSessionException(String message, Throwable cause, boolean enableSuppression,
55+
boolean writableStackTrace) {
56+
super(message, cause, enableSuppression, writableStackTrace);
57+
}
58+
}
59+
60+
private static final class TokenBaseOpenBisSession implements OpenBisSession {
61+
62+
private final String token;
63+
private final IApplicationServerApi applicationServer;
64+
65+
66+
private TokenBaseOpenBisSession(String token, String applicationServerUrl) {
67+
applicationServer = ApiV3.applicationServer(applicationServerUrl);
68+
try {
69+
if (!applicationServer.isSessionActive(token)) {
70+
throw new IllegalArgumentException("Session no longer active.");
71+
}
72+
} catch (UserFailureException userFailureException) {
73+
throw new IllegalArgumentException(userFailureException.getMessage());
74+
}
75+
this.token = token;
76+
}
77+
78+
@Override
79+
public String getToken() {
80+
return token;
81+
}
82+
83+
@Override
84+
public void close() {
85+
applicationServer.logout(token);
86+
}
87+
}
88+
89+
private static final class AutoCloseableOpenBisSession implements OpenBisSession, Refreshable {
90+
91+
private static final Logger log = getLogger(AutoCloseableOpenBisSession.class);
92+
93+
private String token;
94+
private final IApplicationServerApi apiV3;
95+
private final String userName;
96+
private final String password;
97+
98+
private AutoCloseableOpenBisSession(String userName, String password, String applicationServerApiUrl) {
99+
requireNonNull(applicationServerApiUrl, "applicationServerApiUrl must not be null");
100+
apiV3 = ApiV3.applicationServer(applicationServerApiUrl);
101+
this.password = password;
102+
this.userName = userName;
103+
login();
104+
}
105+
106+
107+
@Override
108+
public void refresh() {
109+
logout();
110+
login();
111+
}
112+
113+
private void login() throws OpenBisSessionException {
114+
String sessionToken = apiV3.login(userName, password);
115+
if (sessionToken == null) {
116+
throw new OpenBisSessionException("No session token generated.");
117+
}
118+
token = sessionToken;
119+
log.debug("Successfully logged in");
120+
}
121+
122+
private void logout() {
123+
apiV3.logout(token);
124+
token = null;
125+
log.debug("Successfully logged out");
126+
}
127+
128+
public String getToken() {
129+
return token;
130+
}
131+
132+
@Override
133+
public void close() {
134+
logout();
135+
}
136+
}
137+
138+
public interface OpenBisSession extends AutoCloseable {
139+
140+
String getToken();
141+
142+
@Override
143+
void close();
144+
}
145+
146+
public interface Refreshable {
147+
void refresh();
148+
}
149+
public class ApiV3 {
150+
151+
private ApiV3() {
152+
}
153+
154+
public static IApplicationServerApi applicationServer(String url) {
155+
return HttpInvokerUtils.createServiceStub(IApplicationServerApi.class, url, 100_000L);
156+
}
157+
public static IDataStoreServerApi dataStoreServer(String url) {
158+
return HttpInvokerUtils.createStreamSupportingServiceStub(IDataStoreServerApi.class, url, 100_000L);
159+
}
160+
161+
}
162+
}

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/translation/SimpleOpenBisTermMapper.java

-59
This file was deleted.

project-management-infrastructure/src/main/java/life/qbic/projectmanagement/infrastructure/sample/translation/VocabularyCode.java

-17
This file was deleted.

0 commit comments

Comments
 (0)