Skip to content

Commit

Permalink
Bugfix: Bridgehead Configuration Fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 8, 2024
1 parent ed7e770 commit a3045ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
23 changes: 17 additions & 6 deletions src/main/java/de/samply/bridgehead/BridgeheadConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import de.samply.app.ProjectManagerConst;
import jakarta.annotation.PostConstruct;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;

@Slf4j
@Configuration
Expand Down Expand Up @@ -51,7 +54,7 @@ private void replaceHyphenInBridgeheads() {
}

private void logBridgeheads() {
log.info("Registered bridgeheads: ("+ config.keySet().size()+")");
log.info("Registered bridgeheads: (" + config.keySet().size() + ")");
config.keySet().stream().sorted().forEach(bridgehead -> {
log.info("\t- " + bridgehead + " (" + getHumanReadable(bridgehead) + ")");
});
Expand Down Expand Up @@ -79,17 +82,25 @@ public boolean isRegisteredBridgehead(String bridgehead) {
return config.keySet().contains(bridgehead);
}

public String getFocusBeamId(String bridgehead) {
return config.get(bridgehead).getFocusBeamId();
public Optional<String> getFocusBeamId(String bridgehead) {
return getProperty(bridgehead, bridgeheadConfig -> bridgeheadConfig.getFocusBeamId());
}

public String getHumanReadable(String bridgehead) {
return config.get(bridgehead).getHumanReadable();
public Optional<String> getHumanReadable(String bridgehead) {
return getProperty(bridgehead, bridgeheadConfig -> bridgeheadConfig.getHumanReadable());
}

public Optional<String> getTokenManagerId(String bridgehead) {
return getProperty(bridgehead, bridgeheadConfig -> bridgeheadConfig.getTokenManagerId());
}

Optional<String> getProperty(@NotNull String bridgehead, Function<BridgeheadConfig, String> propertyGetter) {
BridgeheadConfig bridgeheadConfig = config.get(bridgehead);
return Optional.ofNullable((bridgeheadConfig != null) ? bridgeheadConfig.getTokenManagerId() : null);
if (bridgeheadConfig == null) {
return Optional.empty();
}
String result = propertyGetter.apply(bridgeheadConfig);
return StringUtils.hasText(result) ? Optional.of(result) : Optional.empty();
}

public Optional<String> getBridgeheadForExplorerId(String explorerId) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/de/samply/exporter/focus/BeamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Optional;
import java.util.UUID;

@Service
Expand Down Expand Up @@ -49,11 +50,11 @@ public String generateId() {
}

private String fetchFocusBeamId(String bridgehead) throws BeamServiceException {
String focusId = bridgeheadConfiguration.getFocusBeamId(bridgehead);
if (!StringUtils.hasText(focusId)) {
Optional<String> focusId = bridgeheadConfiguration.getFocusBeamId(bridgehead);
if (focusId.isEmpty()) {
throw new BeamServiceException("Focus Beam ID for bridgehead " + bridgehead + " not found");
}
return focusId;
return focusId.get();
}

private String fetchFileDispatcherId(String bridgehead) throws BeamServiceException {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/de/samply/frontend/dto/DtoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.function.Supplier;

@Component
Expand Down Expand Up @@ -106,9 +107,9 @@ public ProjectBridgehead convert(@NotNull de.samply.db.model.ProjectBridgehead p
);
}

public String fetchHumanReadableBridgehead(@NotNull de.samply.db.model.ProjectBridgehead projectBridgehead){
String result = bridgeheadConfiguration.getHumanReadable(projectBridgehead.getBridgehead());
return (result != null) ? result : projectBridgehead.getBridgehead();
public String fetchHumanReadableBridgehead(@NotNull de.samply.db.model.ProjectBridgehead projectBridgehead) {
Optional<String> humanReadable = bridgeheadConfiguration.getHumanReadable(projectBridgehead.getBridgehead());
return (humanReadable.isPresent()) ? humanReadable.get() : projectBridgehead.getBridgehead();
}

public static User convert(@NotNull de.samply.db.model.ProjectBridgeheadUser projectBridgeheadUser) {
Expand Down

0 comments on commit a3045ce

Please sign in to comment.