Skip to content

Commit

Permalink
Merge pull request #87 from GReD-Clermont/5_18_0
Browse files Browse the repository at this point in the history
5.18.0
  • Loading branch information
ppouchin authored Mar 22, 2024
2 parents f2633ec + fb20703 commit ee77a10
Show file tree
Hide file tree
Showing 71 changed files with 1,761 additions and 989 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,42 @@ jobs:

env:
HAVE_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN != '' }}
HAVE_SONAR_DETAILS: ${{ vars.SONAR_PROJECTKEY != '' && vars.SONAR_ORGANIZATION != '' }}
HAVE_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN != '' }}

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout omero-test-infra
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: openmicroscopy/omero-test-infra
submodules: true
path: .omero
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}
- name: Login to Docker Hub
if: ${{ env.HAVE_DOCKERHUB_TOKEN == 'true' }}
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -63,20 +64,20 @@ jobs:
- name: Set folders ownership back to current user
run: sudo chown -R $(id -u):$(id -g) $GITHUB_WORKSPACE && sudo chown -R $(id -u):$(id -g) $HOME
- name: Sonar analysis
if: ${{ env.HAVE_SONAR_TOKEN == 'true' }}
if: ${{ env.HAVE_SONAR_TOKEN == 'true' && env.HAVE_SONAR_DETAILS == 'true' }}
run: mvn sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.projectKey=$SONAR_PROJECTKEY -Dsonar.organization=$SONAR_ORGANIZATION
env:
SONAR_PROJECTKEY: GReD-Clermont_simple-omero-client
SONAR_ORGANIZATION: gred-clermont
SONAR_URL: https://sonarcloud.io
SONAR_PROJECTKEY: ${{ vars.SONAR_PROJECTKEY }}
SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }}
SONAR_URL: ${{ vars.SONAR_URL }}
GITHUB_TOKEN: ${{ github.token }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload to codecov after successful tests
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: jars
path: |
Expand All @@ -89,19 +90,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
gpg-private-key: ${{ secrets.GPG_KEY }} # Value of the GPG private key to import
gpg-passphrase: GPG_PASSPHRASE # env variable for GPG private key passphrase
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<groupId>fr.igred</groupId>
<artifactId>simple-omero-client</artifactId>
<version>5.17.0</version>
<version>5.18.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Simple OMERO Client</name>
Expand Down
221 changes: 115 additions & 106 deletions src/main/java/fr/igred/omero/AnnotatableWrapper.java

Large diffs are not rendered by default.

271 changes: 148 additions & 123 deletions src/main/java/fr/igred/omero/Browser.java

Large diffs are not rendered by default.

66 changes: 39 additions & 27 deletions src/main/java/fr/igred/omero/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.stream.Collectors;

import static fr.igred.omero.GenericObjectWrapper.flatten;
import static fr.igred.omero.exception.ExceptionHandler.call;


/**
Expand Down Expand Up @@ -196,7 +197,9 @@ public void delete(Collection<? extends GenericObjectWrapper<?>> objects)
}
}
if (!objects.isEmpty()) {
delete(objects.stream().map(GenericObjectWrapper::asIObject).collect(Collectors.toList()));
delete(objects.stream()
.map(GenericObjectWrapper::asIObject)
.collect(Collectors.toList()));
}
}

Expand Down Expand Up @@ -272,7 +275,9 @@ public void deleteTable(TableWrapper table)
*/
public void deleteTables(Collection<? extends TableWrapper> tables)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
deleteFiles(tables.stream().map(TableWrapper::getId).toArray(Long[]::new));
deleteFiles(tables.stream()
.map(TableWrapper::getId)
.toArray(Long[]::new));
}


Expand All @@ -290,14 +295,15 @@ public void deleteTables(Collection<? extends TableWrapper> tables)
*/
public ExperimenterWrapper getUser(String username)
throws ExecutionException, ServiceException, AccessException {
ExperimenterData experimenter = ExceptionHandler.of(getAdminFacility(),
a -> a.lookupExperimenter(getCtx(), username))
.handleOMEROException("Cannot retrieve user: " + username)
.get();
if (experimenter != null) {
return new ExperimenterWrapper(experimenter);
ExperimenterData user = call(getAdminFacility(),
a -> a.lookupExperimenter(getCtx(),
username),
"Cannot retrieve user: " + username);
if (user != null) {
return new ExperimenterWrapper(user);
} else {
throw new NoSuchElementException(String.format("User not found: %s", username));
String msg = String.format("User not found: %s", username);
throw new NoSuchElementException(msg);
}
}

Expand All @@ -315,7 +321,9 @@ public ExperimenterWrapper getUser(String username)
*/
public ExperimenterWrapper getUser(long userId)
throws ServiceException, OMEROServerError {
Experimenter user = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()).getExperimenter(userId))
Experimenter user = ExceptionHandler.of(getGateway(),
g -> g.getAdminService(getCtx())
.getExperimenter(userId))
.rethrow(ApiUsageException.class,
(m, e) -> new NoSuchElementException(m),
"User not found: " + userId)
Expand All @@ -339,13 +347,14 @@ public ExperimenterWrapper getUser(long userId)
*/
public GroupWrapper getGroup(String groupName)
throws ExecutionException, ServiceException, AccessException {
GroupData group = ExceptionHandler.of(getAdminFacility(), a -> a.lookupGroup(getCtx(), groupName))
.handleOMEROException("Cannot retrieve group: " + groupName)
.get();
GroupData group = call(getAdminFacility(),
a -> a.lookupGroup(getCtx(), groupName),
"Cannot retrieve group: " + groupName);
if (group != null) {
return new GroupWrapper(group);
} else {
throw new NoSuchElementException(String.format("Group not found: %s", groupName));
String msg = String.format("Group not found: %s", groupName);
throw new NoSuchElementException(msg);
}
}

Expand All @@ -363,7 +372,9 @@ public GroupWrapper getGroup(String groupName)
*/
public GroupWrapper getGroup(long groupId)
throws ServiceException, OMEROServerError {
ExperimenterGroup group = ExceptionHandler.of(getGateway(), g -> g.getAdminService(getCtx()).getGroup(groupId))
ExperimenterGroup group = ExceptionHandler.of(getGateway(),
g -> g.getAdminService(getCtx())
.getGroup(groupId))
.rethrow(ApiUsageException.class,
(m, e) -> new NoSuchElementException(m),
"Group not found: " + groupId)
Expand All @@ -378,21 +389,21 @@ public GroupWrapper getGroup(long groupId)
*
* @return See above.
*
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
* @throws ServiceException Cannot connect to OMERO.
* @throws AccessException Cannot access data.
*/
public List<GroupWrapper> getGroups()
throws ServiceException, AccessException {
String error = "Cannot retrieve the groups on OMERO";
return ExceptionHandler.of(getGateway(),
g -> g.getAdminService(getCtx()).lookupGroups())
.handleOMEROException(error)
.get()
.stream()
.filter(Objects::nonNull)
.map(GroupData::new)
.map(GroupWrapper::new)
.collect(Collectors.toList());
List<ExperimenterGroup> groups = call(getGateway(),
g -> g.getAdminService(getCtx())
.lookupGroups(),
error);
return groups.stream()
.filter(Objects::nonNull)
.map(GroupData::new)
.map(GroupWrapper::new)
.collect(Collectors.toList());
}


Expand All @@ -412,8 +423,9 @@ public List<GroupWrapper> getGroups()
public Client sudoGetUser(String username)
throws ServiceException, AccessException, ExecutionException {
ExperimenterWrapper sudoUser = getUser(username);
long groupId = sudoUser.getDefaultGroup().getId();

SecurityContext context = new SecurityContext(sudoUser.getDefaultGroup().getId());
SecurityContext context = new SecurityContext(groupId);
context.setExperimenter(sudoUser.asDataObject());
context.sudo();

Expand Down
40 changes: 28 additions & 12 deletions src/main/java/fr/igred/omero/GatewayWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;

import static fr.igred.omero.exception.ExceptionHandler.call;


/**
* Basic class, contains the gateway, the security context, and multiple facilities.
Expand Down Expand Up @@ -175,8 +177,10 @@ public long getCurrentGroupId() {
* @throws ServiceException If the connection is broken, or not logged in
*/
public String getSessionId() throws ServiceException {
return ExceptionHandler.of(gateway, g -> g.getSessionId(user.asDataObject()))
.rethrow(DSOutOfServiceException.class, ServiceException::new,
return ExceptionHandler.of(gateway,
g -> g.getSessionId(user.asDataObject()))
.rethrow(DSOutOfServiceException.class,
ServiceException::new,
"Could not retrieve session ID")
.get();
}
Expand Down Expand Up @@ -222,7 +226,10 @@ public void connect(String hostname, int port, String sessionId)
*/
public void connect(String hostname, int port, String username, char[] password, Long groupID)
throws ServiceException {
LoginCredentials cred = new LoginCredentials(username, String.valueOf(password), hostname, port);
LoginCredentials cred = new LoginCredentials(username,
String.valueOf(password),
hostname,
port);
cred.setGroupID(groupID);
connect(cred);
}
Expand All @@ -242,7 +249,10 @@ public void connect(String hostname, int port, String username, char[] password,
*/
public void connect(String hostname, int port, String username, char[] password)
throws ServiceException {
connect(new LoginCredentials(username, String.valueOf(password), hostname, port));
connect(new LoginCredentials(username,
String.valueOf(password),
hostname,
port));
}


Expand Down Expand Up @@ -323,7 +333,8 @@ public BrowseFacility getBrowseFacility() throws ExecutionException {
*/
public IQueryPrx getQueryService() throws ServiceException {
return ExceptionHandler.of(gateway, g -> g.getQueryService(ctx))
.rethrow(DSOutOfServiceException.class, ServiceException::new,
.rethrow(DSOutOfServiceException.class,
ServiceException::new,
"Could not retrieve Query Service")
.get();
}
Expand Down Expand Up @@ -399,7 +410,8 @@ public AdminFacility getAdminFacility() throws ExecutionException {
public OMEROMetadataStoreClient getImportStore() throws ServiceException {
storeUses.incrementAndGet();
return ExceptionHandler.of(this, GatewayWrapper::getImportStoreLocked)
.rethrow(DSOutOfServiceException.class, ServiceException::new,
.rethrow(DSOutOfServiceException.class,
ServiceException::new,
"Could not retrieve import store")
.get();
}
Expand Down Expand Up @@ -428,7 +440,9 @@ public void closeImport() {
*/
public List<IObject> findByQuery(String query)
throws ServiceException, OMEROServerError {
return ExceptionHandler.of(gateway, g -> g.getQueryService(ctx).findAllByQuery(query, null))
return ExceptionHandler.of(gateway,
g -> g.getQueryService(ctx)
.findAllByQuery(query, null))
.handleServiceOrServer("Query failed: " + query)
.get();
}
Expand All @@ -447,9 +461,9 @@ public List<IObject> findByQuery(String query)
*/
public IObject save(IObject object)
throws ServiceException, AccessException, ExecutionException {
return ExceptionHandler.of(getDm(), d -> d.saveAndReturnObject(ctx, object))
.handleOMEROException("Cannot save object")
.get();
return call(getDm(),
d -> d.saveAndReturnObject(ctx, object),
"Cannot save object");
}


Expand All @@ -467,7 +481,8 @@ public IObject save(IObject object)
void delete(IObject object)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
final long wait = 500L;
ExceptionHandler.ofConsumer(getDm(), d -> d.delete(ctx, object).loop(10, wait))
ExceptionHandler.ofConsumer(getDm(),
d -> d.delete(ctx, object).loop(10, wait))
.rethrow(InterruptedException.class)
.handleException("Cannot delete object")
.rethrow();
Expand All @@ -488,7 +503,8 @@ void delete(IObject object)
void delete(List<IObject> objects)
throws ServiceException, AccessException, ExecutionException, OMEROServerError, InterruptedException {
final long wait = 500L;
ExceptionHandler.ofConsumer(getDm(), d -> d.delete(ctx, objects).loop(10, wait))
ExceptionHandler.ofConsumer(getDm(),
d -> d.delete(ctx, objects).loop(10, wait))
.rethrow(InterruptedException.class)
.handleException("Cannot delete objects")
.rethrow();
Expand Down
Loading

0 comments on commit ee77a10

Please sign in to comment.