Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/org/phoebus/channelfinder/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.phoebus.channelfinder.example.PopulateService;
import org.phoebus.channelfinder.processors.ChannelProcessor;
import org.phoebus.channelfinder.configuration.ChannelProcessor;
import org.phoebus.channelfinder.configuration.PopulateDBConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
Expand All @@ -43,7 +43,7 @@
@SpringBootApplication
public class Application implements ApplicationRunner {

static final Logger logger = Logger.getLogger(Application.class.getName());
private static final Logger logger = Logger.getLogger(Application.class.getName());

public static void main(String[] args) {
// Set the java truststore used by channelfinder
Expand Down Expand Up @@ -72,7 +72,7 @@ private static void configureTruststore() {
}
}

@Autowired PopulateService service;
@Autowired PopulateDBConfiguration service;

public void run(ApplicationArguments args) throws Exception {
if (args.containsOption("demo-data")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.common;

public class CFResourceDescriptors {

Check warning on line 3 in src/main/java/org/phoebus/channelfinder/common/CFResourceDescriptors.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a private constructor to hide the implicit public one.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BLI1F1th5WJNemt&open=AZro6BLI1F1th5WJNemt&pullRequest=193

public static final String CF_SERVICE = "ChannelFinder";
public static final String CF_SERVICE_INFO = CF_SERVICE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.phoebus.channelfinder.epics;
package org.phoebus.channelfinder.common;

import static org.phoebus.channelfinder.epics.ChannelFinderEpicsService.COLUMN_CHANNEL_NAME;
import static org.phoebus.channelfinder.epics.ChannelFinderEpicsService.COLUMN_OWNER;
import static org.phoebus.channelfinder.service.ChannelFinderEpicsService.COLUMN_CHANNEL_NAME;
import static org.phoebus.channelfinder.service.ChannelFinderEpicsService.COLUMN_OWNER;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.common;

/**
* Utility class to assist in handling of text.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder.processors.aa;
package org.phoebus.channelfinder.configuration;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
Expand All @@ -14,8 +14,11 @@
import org.apache.commons.lang3.StringUtils;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.entity.Property;
import org.phoebus.channelfinder.processors.ChannelProcessor;
import org.phoebus.channelfinder.processors.ChannelProcessorInfo;
import org.phoebus.channelfinder.service.external.ArchiverClient;
import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo;
import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction;
import org.phoebus.channelfinder.service.model.archiver.aa.ArchivePVOptions;
import org.phoebus.channelfinder.service.model.archiver.aa.ArchiverInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.phoebus.channelfinder.processors;
package org.phoebus.channelfinder.configuration;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.List;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.service.model.archiver.ChannelProcessorInfo;

public interface ChannelProcessor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** */
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.configuration;

/*
* #%L
Expand Down Expand Up @@ -41,6 +41,7 @@
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.phoebus.channelfinder.common.TextUtil;
import org.phoebus.channelfinder.entity.Property;
import org.phoebus.channelfinder.entity.Tag;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -101,7 +102,7 @@
return this.ES_TAG_INDEX;
}

public String getES_PROPERTY_INDEX() {

Check warning on line 105 in src/main/java/org/phoebus/channelfinder/configuration/ElasticConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BGY1F1th5WJNekV&open=AZro6BGY1F1th5WJNekV&pullRequest=193
return this.ES_PROPERTY_INDEX;
}

Expand Down Expand Up @@ -215,7 +216,7 @@
*
* @param client client connected to elasticsearch
*/
void elasticIndexValidation(ElasticsearchClient client) {
public void elasticIndexValidation(ElasticsearchClient client) {
validateIndex(client, ES_CHANNEL_INDEX, "/channel_mapping.json");
validateIndex(client, ES_TAG_INDEX, "/tag_mapping.json");
validateIndex(client, ES_PROPERTY_INDEX, "/properties_mapping.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.configuration;

import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.annotation.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder.example;
package org.phoebus.channelfinder.configuration;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.Refresh;
Expand All @@ -25,7 +25,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.phoebus.channelfinder.ElasticConfig;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.entity.Property;
import org.phoebus.channelfinder.entity.Tag;
Expand Down Expand Up @@ -56,9 +55,9 @@
* @author Kunal Shroff
*/
@Configuration
public class PopulateService {
public class PopulateDBConfiguration {

private static final Logger logger = Logger.getLogger(PopulateService.class.getName());
private static final Logger logger = Logger.getLogger(PopulateDBConfiguration.class.getName());
public static final String DEVICE_POWER_SUPPLY = "power supply";
public static final String DEVICE_MAGNET = "magnet";
public static final String UNIT_TEMP = "temperature";
Expand Down Expand Up @@ -461,7 +460,7 @@
return result;
}

private Collection<Channel> insertBigMagnets(

Check warning on line 463 in src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 8 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BGy1F1th5WJNekf&open=AZro6BGy1F1th5WJNekf&pullRequest=193
Map<Integer, List<Integer>> tokens,
AtomicInteger channelInCell,
int count,
Expand Down Expand Up @@ -658,7 +657,7 @@
return channels;
}

private void insertPowerSupplyChannels(

Check warning on line 660 in src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 9 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BGy1F1th5WJNekg&open=AZro6BGy1F1th5WJNekg&pullRequest=193
ArrayList<Channel> channels,
Map<Integer, List<Integer>> tokens,
AtomicInteger channelInCell,
Expand Down Expand Up @@ -843,7 +842,7 @@
"{" + "GV" + "}Opn-Sw",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"valve",
"position",
SIGTYPE_SWITCH));
Expand All @@ -857,7 +856,7 @@
"{" + "GV" + "}Opn-St",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"valve",
"position",
SIGTYPE_STATUS));
Expand All @@ -883,7 +882,7 @@
"{" + dev + "}P-RB",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"gauge",
"pressure",
SIGTYPE_READBACK));
Expand All @@ -897,7 +896,7 @@
"{" + dev + OK_ST,
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"gauge",
"error",
SIGTYPE_STATUS));
Expand All @@ -922,7 +921,7 @@
"{" + dev + "}I-RB",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"pump",
UNIT_CURRENT,
SIGTYPE_READBACK));
Expand All @@ -936,7 +935,7 @@
"{" + dev + "}P-RB",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"pump",
"pressure",
SIGTYPE_READBACK));
Expand All @@ -950,7 +949,7 @@
"{" + dev + "}On-Sw",
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"pump",
UNIT_POWER,
SIGTYPE_SWITCH));
Expand All @@ -964,7 +963,7 @@
"{" + dev + OK_ST,
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"pump",
"error",
SIGTYPE_STATUS));
Expand All @@ -978,7 +977,7 @@
"{" + dev + ON_ST,
loc,
cell,
PopulateService.ELEMENT_VACUUM,
PopulateDBConfiguration.ELEMENT_VACUUM,
"pump",
UNIT_POWER,
SIGTYPE_STATUS));
Expand Down Expand Up @@ -1066,7 +1065,7 @@
return channels;
}

private Collection<Channel> insertBpms(

Check warning on line 1068 in src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 8 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BGy1F1th5WJNeki&open=AZro6BGy1F1th5WJNeki&pullRequest=193
Map<Integer, List<Integer>> tokens,
AtomicInteger channelInCell,
int count,
Expand Down Expand Up @@ -1208,7 +1207,7 @@
Integer val = entry.getValue().remove(randIndex);
channel
.getProperties()
.add(new Property("group" + entry.getKey(), powner, String.valueOf(val)));

Check failure on line 1210 in src/main/java/org/phoebus/channelfinder/configuration/PopulateDBConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use already-defined constant 'GROUP' instead of duplicating its value here.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BGy1F1th5WJNekc&open=AZro6BGy1F1th5WJNekc&pullRequest=193
channel.getTags().add(new Tag("group" + entry.getKey() + "_" + val, towner));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -36,7 +36,7 @@
boolean ldap_enabled;

@Value("${ldap.urls:ldaps://localhost:389/}")
String ldap_url;

Check warning on line 39 in src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "ldap_url" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BFn1F1th5WJNekA&open=AZro6BFn1F1th5WJNekA&pullRequest=193

@Value("${ldap.user.dn.pattern}")
String ldap_user_dn_pattern;
Expand All @@ -49,13 +49,13 @@

/** Embedded LDAP configuration properties */
@Value("${embedded_ldap.enabled:false}")
boolean embedded_ldap_enabled;

Check warning on line 52 in src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "embedded_ldap_enabled" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BFn1F1th5WJNekE&open=AZro6BFn1F1th5WJNekE&pullRequest=193

@Value("${embedded_ldap.urls:ldaps://localhost:389/}")
String embedded_ldap_url;

@Value("${embedded_ldap.user.dn.pattern}")
String embedded_ldap_user_dn_pattern;

Check warning on line 58 in src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "embedded_ldap_user_dn_pattern" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BFn1F1th5WJNekG&open=AZro6BFn1F1th5WJNekG&pullRequest=193

@Value("${embedded_ldap.groups.search.base}")
String embedded_ldap_groups_search_base;
Expand All @@ -74,7 +74,7 @@
String[] demo_auth_users;

@Value("${demo_auth.pwds}")
String[] demo_auth_pwds;

Check warning on line 77 in src/main/java/org/phoebus/channelfinder/configuration/WebSecurityConfig.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "demo_auth_pwds" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BFn1F1th5WJNekM&open=AZro6BFn1F1th5WJNekM&pullRequest=193

@Value("${demo_auth.roles}")
String[] demo_auth_roles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.repository;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
Expand Down Expand Up @@ -49,6 +49,9 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.annotation.PreDestroy;
import org.phoebus.channelfinder.common.CFResourceDescriptors;
import org.phoebus.channelfinder.common.TextUtil;
import org.phoebus.channelfinder.configuration.ElasticConfig;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.entity.Property;
import org.phoebus.channelfinder.entity.SearchResult;
Expand All @@ -72,7 +75,7 @@

@Autowired ElasticConfig esService;

@Autowired

Check warning on line 78 in src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BET1F1th5WJNeji&open=AZro6BET1F1th5WJNeji&pullRequest=193
@Qualifier("indexClient")
ElasticsearchClient client;

Expand Down Expand Up @@ -309,7 +312,7 @@
for (Future<List<Channel>> future : futures) {
try {
allSaved.addAll(future.get());
} catch (Exception e) {

Check warning on line 315 in src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BET1F1th5WJNejo&open=AZro6BET1F1th5WJNejo&pullRequest=193
logger.log(Level.SEVERE, "Bulk saving failed", e);
}
}
Expand Down Expand Up @@ -425,7 +428,7 @@
.size(esService.getES_QUERY_SIZE())
.sort(SortOptions.of(s -> s.field(FieldSort.of(f -> f.field("name")))));
SearchResponse<Channel> response = client.search(searchBuilder.build(), Channel.class);
return response.hits().hits().stream().map(Hit::source).collect(Collectors.toList());

Check warning on line 431 in src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BET1F1th5WJNejs&open=AZro6BET1F1th5WJNejs&pullRequest=193
} catch (ElasticsearchException | IOException e) {
logger.log(Level.SEVERE, TextUtil.FAILED_TO_FIND_ALL_CHANNELS, e);
throw new ResponseStatusException(
Expand Down Expand Up @@ -540,7 +543,7 @@
count = response.hits().total().value();
}
return new SearchResult(hits.stream().map(Hit::source).collect(Collectors.toList()), count);
} catch (Exception e) {

Check warning on line 546 in src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either log this exception and handle it, or rethrow it with some contextual information.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BET1F1th5WJNejv&open=AZro6BET1F1th5WJNejv&pullRequest=193
String message =
MessageFormat.format(TextUtil.SEARCH_FAILED_CAUSE, searchParameters, e.getMessage());
logger.log(Level.SEVERE, message, e);
Expand Down Expand Up @@ -763,7 +766,7 @@

@Override
public void deleteAllById(Iterable<? extends String> ids) {
// TODO Auto-generated method stub

Check warning on line 769 in src/main/java/org/phoebus/channelfinder/repository/ChannelRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BET1F1th5WJNejx&open=AZro6BET1F1th5WJNejx&pullRequest=193

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.repository;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
Expand Down Expand Up @@ -31,6 +31,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.StreamSupport;
import org.phoebus.channelfinder.common.TextUtil;
import org.phoebus.channelfinder.configuration.ElasticConfig;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.entity.Property;
import org.phoebus.channelfinder.entity.Property.OnlyNameOwnerProperty;
Expand All @@ -56,7 +58,7 @@

@Autowired ElasticConfig esService;

@Autowired ChannelRepository channelRepository;

Check warning on line 61 in src/main/java/org/phoebus/channelfinder/repository/PropertyRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6BFe1F1th5WJNej2&open=AZro6BFe1F1th5WJNej2&pullRequest=193

ObjectMapper objectMapper =
new ObjectMapper().addMixIn(Property.class, OnlyNameOwnerProperty.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phoebus.channelfinder;
package org.phoebus.channelfinder.repository;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
Expand Down Expand Up @@ -32,6 +32,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.StreamSupport;
import org.phoebus.channelfinder.common.TextUtil;
import org.phoebus.channelfinder.configuration.ElasticConfig;
import org.phoebus.channelfinder.entity.Channel;
import org.phoebus.channelfinder.entity.Tag;
import org.phoebus.channelfinder.entity.Tag.OnlyTag;
Expand All @@ -51,7 +53,7 @@

private static final Logger logger = Logger.getLogger(TagRepository.class.getName());

@Autowired ElasticConfig esService;

Check warning on line 56 in src/main/java/org/phoebus/channelfinder/repository/TagRepository.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=ChannelFinder_ChannelFinderService&issues=AZro6A-c1F1th5WJNejY&open=AZro6A-c1F1th5WJNejY&pullRequest=193

@Autowired
@Qualifier("indexClient")
Expand Down
Loading