Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): unify properties files #2766

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.eclipse.sw360.datahandler.db.ComponentDatabaseHandler;
import org.eclipse.sw360.datahandler.db.PackageDatabaseHandler;
import org.eclipse.sw360.datahandler.db.ProjectDatabaseHandler;
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
import org.eclipse.sw360.datahandler.thrift.CycloneDxComponentType;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.RequestSummary;
Expand Down Expand Up @@ -95,7 +94,7 @@ public RequestSummary exportSbom(String projectId, String bomType, Boolean inclu
linkedPackageIds.addAll(idsMap.get(SW360Constants.PACKAGE_IDS));
}

if (PermissionUtils.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) {
if (SW360Constants.IS_COMPONENT_VISIBILITY_RESTRICTION_ENABLED) {
List<Release> releaseList = componentDatabaseHandler.getAccessibleReleaseSummary(user);
Set<String> releaseListIds = releaseList.stream().map(Release::getId).collect(Collectors.toSet());
linkedReleaseIds = CollectionUtils.intersection(releaseListIds, linkedReleaseIds).stream().collect(Collectors.toSet());
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import com.ibm.cloud.cloudant.v1.model.DocumentResult;
import com.google.common.collect.*;

import org.eclipse.sw360.common.utils.BackendUtils;
import org.eclipse.sw360.commonIO.AttachmentFrontendUtils;
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.DatabaseConstants;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;
import org.eclipse.sw360.datahandler.common.Duration;
import org.eclipse.sw360.datahandler.common.SW360Constants;
Expand Down Expand Up @@ -62,7 +62,6 @@
import org.eclipse.sw360.mail.MailUtil;
import org.apache.logging.log4j.Logger;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.thrift.TException;
import org.eclipse.sw360.spdx.SpdxBOMImporter;
Expand All @@ -76,7 +75,6 @@

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.file.*;
Expand Down Expand Up @@ -1261,7 +1259,7 @@ private Set<String> extractAttachmentNameWithType(Set<Attachment> attachments, C
}

private void setMainlineState(Release updated, User user, Release current) {
boolean isMainlineStateDisabled = !(BackendUtils.MAINLINE_STATE_ENABLED_FOR_USER
boolean isMainlineStateDisabled = !(SW360Constants.MAINLINE_STATE_ENABLED_FOR_USER
|| PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user));

if ((null == current || null == current.getMainlineState()) && isMainlineStateDisabled) {
Expand Down Expand Up @@ -1345,7 +1343,7 @@ private void autosetEccFieldsForReleaseWithDownloadUrl(Release release) {
eccInfo.setAl(ECC_AUTOSET_VALUE);
eccInfo.setEccn(ECC_AUTOSET_VALUE);
eccInfo.setEccComment(ECC_AUTOSET_COMMENT);
if (DatabaseHandlerUtil.AUTO_SET_ECC_STATUS) {
if (DatabaseConstants.AUTO_SET_ECC_STATUS) {
eccInfo.setEccStatus(ECCStatus.APPROVED);
}
eccInfo.setAssessmentDate(SW360Utils.getCreatedOn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -64,6 +63,7 @@
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseRepositoryCloudantClient;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.DatabaseConstants;
import org.eclipse.sw360.datahandler.common.DatabaseSettings;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException;
Expand Down Expand Up @@ -140,42 +140,14 @@ public class DatabaseHandlerUtil {
public static final String SEPARATOR = " -> ";
private static ChangeLogsRepository changeLogRepository;
private static ObjectMapper mapper = initAndGetObjectMapper();
public static final String PROPERTIES_FILE_PATH = "/sw360.properties";
private static final String SVM_JSON_LOG_OUTPUT_LOCATION;
private static final String SVM_JSON_FILE_PREFIX = "svm_json_output_";
private static final String SVM_JSON_FILE_SUFFIX = ".json";
private static final String SVM_JSON_LOG_OUTPUT_FILE_PERMISSION = "rw-------";
private static final String ATTACHMENT_ID = "attachmentId_";
private static final String DOCUMENT_ID = "documentId_";
private static final boolean IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED;
private static final String ATTACHMENT_STORE_FILE_SYSTEM_LOCATION;
private static final String ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION;
private static ExecutorService ATTACHMENT_FILE_SYSTEM_STORE_THREAD_POOL = Executors.newFixedThreadPool(5);
private static final String ATTACHMENT_DELETE_NO_OF_DAYS;
private static final boolean IS_SW360CHANGELOG_ENABLED;
private static final String CHANGE_LOG_CONFIG_FILE_PATH;
private static final String SW360CHANGELOG_OUTPUT_PATH;
private static boolean isChangeLogDisabledMessageLogged = false;
private static boolean isLiferayEnvVarNotPresent = true;
public static final boolean AUTO_SET_ECC_STATUS;

static {
Properties props = CommonUtils.loadProperties(DatabaseSettings.class, PROPERTIES_FILE_PATH);
SVM_JSON_LOG_OUTPUT_LOCATION = props.getProperty("svm.json.log.output.location", "/tmp");
ATTACHMENT_STORE_FILE_SYSTEM_LOCATION = props.getProperty("attachment.store.file.system.location",
"/opt/sw360tempattachments");
ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION = props.getProperty("attachment.store.file.system.permission",
"rwx------");
IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED = Boolean.parseBoolean(props.getProperty("enable.attachment.store.to.file.system", "false"));
ATTACHMENT_DELETE_NO_OF_DAYS = props.getProperty("attachemnt.delete.no.of.days",
"30");
IS_SW360CHANGELOG_ENABLED = Boolean.parseBoolean(props.getProperty("enable.sw360.change.log", "false"));
CHANGE_LOG_CONFIG_FILE_PATH = props.getProperty("sw360changelog.config.file.location",
"/etc/sw360/log4j2.xml");
SW360CHANGELOG_OUTPUT_PATH = props.getProperty("sw360changelog.output.path",
"sw360changelog/sw360changelog");
AUTO_SET_ECC_STATUS = Boolean.parseBoolean(props.getProperty("auto.set.ecc.status", "false"));
}

public DatabaseHandlerUtil(DatabaseConnectorCloudant db) {
changeLogRepository = new ChangeLogsRepository(db);
Expand Down Expand Up @@ -525,7 +497,7 @@ public static String convertObjectToJson(Object obj) {
*/
public static <T extends TBase> void addSelectLogs(T newDocVersion, String userEdited, AttachmentConnector attachmentConnector) {

if (!IS_SW360CHANGELOG_ENABLED) {
if (!DatabaseConstants.IS_SW360CHANGELOG_ENABLED) {
if (!isChangeLogDisabledMessageLogged) {
log.info("sw360change log is disabled");
isChangeLogDisabledMessageLogged = true;
Expand All @@ -552,7 +524,7 @@ public static <T extends TBase> void addSelectLogs(T newDocVersion, String userE
};

Thread changeLogsThread = new Thread(changeLogRunnable);
File sw360ChangeLogFileLocation = new File(CHANGE_LOG_CONFIG_FILE_PATH);
File sw360ChangeLogFileLocation = new File(DatabaseConstants.CHANGE_LOG_CONFIG_FILE_PATH);
if (sw360ChangeLogFileLocation.exists()) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation(sw360ChangeLogFileLocation.toURI());
Expand All @@ -564,7 +536,7 @@ public static <T extends TBase> void addSelectLogs(T newDocVersion, String userE
return;
}
String LIFERAY_HOME = env.get("LIFERAY_INSTALL");
configureLog4J(SW360CHANGELOG_OUTPUT_PATH, LIFERAY_HOME);
configureLog4J(DatabaseConstants.SW360CHANGELOG_OUTPUT_PATH, LIFERAY_HOME);
}
changeLogsThread.start();
}
Expand Down Expand Up @@ -948,7 +920,7 @@ private static Runnable prepareFileHandlerRunnable(String content) {
log.info("Preparing to write content to file");
StringBuilder fileNameSb = new StringBuilder(SVM_JSON_FILE_PREFIX)
.append(getTimeStamp().replaceAll(" ", "_").replaceAll(":", "-")).append(SVM_JSON_FILE_SUFFIX);
Path outputFile = Paths.get(SVM_JSON_LOG_OUTPUT_LOCATION, fileNameSb.toString());
Path outputFile = Paths.get(DatabaseConstants.SVM_JSON_LOG_OUTPUT_LOCATION, fileNameSb.toString());
if (!Files.exists(outputFile)) {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString(SVM_JSON_LOG_OUTPUT_FILE_PERMISSION);
FileAttribute<Set<PosixFilePermission>> fileAttribute = PosixFilePermissions.asFileAttribute(perms);
Expand Down Expand Up @@ -988,14 +960,14 @@ private static Runnable prepareFileHandlerRunnable(InputStream content, String u
String attachmentId, String fileName) {
return () -> {
try {
Path outputDir = Paths.get(ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, userEmail, DOCUMENT_ID + documentId,
Path outputDir = Paths.get(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, userEmail, DOCUMENT_ID + documentId,
ATTACHMENT_ID + attachmentId);
Path outputFile = Paths.get(fileName);
Path outputFilePath = outputDir.resolve(outputFile);
log.info("Preparing to store attachment in file system" + outputFilePath);
if (!Files.exists(outputFile)) {
Set<PosixFilePermission> perms = PosixFilePermissions
.fromString(ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION);
.fromString(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_PERMISSION);
FileAttribute<Set<PosixFilePermission>> fileAttribute = PosixFilePermissions.asFileAttribute(perms);
Files.createDirectories(outputDir, fileAttribute);
Files.createFile(outputFilePath, fileAttribute);
Expand All @@ -1016,7 +988,7 @@ private static Runnable prepareFileHandlerRunnable(InputStream content, String u
*/
public static void saveAttachmentInFileSystem(AttachmentConnector attachmentConnector, Set<Attachment> before,
Set<Attachment> after, String userEmail, String documentId) {
if (!IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED) {
if (!DatabaseConstants.IS_STORE_ATTACHMENT_TO_FILE_SYSTEM_ENABLED) {
log.debug("Store attachment to file system is disabled");
return;
}
Expand Down Expand Up @@ -1044,13 +1016,13 @@ public static void saveAttachmentInFileSystem(AttachmentConnector attachmentConn
}

public static RequestStatus deleteOldAttachmentFromFileSystem() {
int noOfDays = Integer.parseInt(ATTACHMENT_DELETE_NO_OF_DAYS);
int noOfDays = Integer.parseInt(DatabaseConstants.ATTACHMENT_DELETE_NO_OF_DAYS);
RequestStatus status = null;
LocalDate todayDate = LocalDate.now();
LocalDate thresholdDateForAttachmentDelete = todayDate.minusDays(noOfDays);
Date thresholdDate = Date.from(thresholdDateForAttachmentDelete.atStartOfDay(ZoneId.systemDefault()).toInstant());
try {
deleteAttachmentAndDirectory(ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, thresholdDate);
deleteAttachmentAndDirectory(DatabaseConstants.ATTACHMENT_STORE_FILE_SYSTEM_LOCATION, thresholdDate);
status = RequestStatus.SUCCESS;
} catch (IOException e) {
log.error("Unable to delete attachment. ", e);
Expand Down Expand Up @@ -1126,4 +1098,3 @@ public static File saveAsTempFile(InputStream inputStream, String prefix, String
return tempFile;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ibm.cloud.cloudant.v1.Cloudant;
import com.google.common.annotations.VisibleForTesting;
Expand All @@ -24,7 +23,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.thrift.TException;
import org.eclipse.sw360.common.utils.BackendUtils;
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.cyclonedx.CycloneDxBOMExporter;
import org.eclipse.sw360.cyclonedx.CycloneDxBOMImporter;
Expand Down Expand Up @@ -685,7 +683,7 @@ private boolean isLinkedReleaseUpdated(Project updated, Project current) {
}

private void setReleaseRelations(Project updated, User user, Project current) {
boolean isMainlineStateDisabled = !(BackendUtils.MAINLINE_STATE_ENABLED_FOR_USER
boolean isMainlineStateDisabled = !(SW360Constants.MAINLINE_STATE_ENABLED_FOR_USER
|| PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user))
&& updated.getReleaseIdToUsageSize() > 0;

Expand Down Expand Up @@ -1319,7 +1317,7 @@ public List<Project> fillClearingStateSummaryIncludingSubprojects(List<Project>

return projects;
}

public Project fillClearingStateSummaryIncludingSubprojectsForSingleProject(Project project, User user) {
final Map<String, Project> allProjectsIdMap = getRefreshedAllProjectsIdMap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.sw360.components.summary.SummaryType;
import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.SW360Constants;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.couchdb.SummaryAwareRepository;
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
Expand Down Expand Up @@ -424,7 +425,7 @@ public Map<PaginationData, List<Project>> getAccessibleProjectsSummary(User user
isUserBelongToBuAndModerator = and(List.of(buAndModorator_visibility_Selector, or(buSelectors)));

Map<String, Object> finalSelector;
if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) {
if (SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) {
finalSelector = typeSelector;
} else {
if (isClearingAdmin) {
Expand Down Expand Up @@ -556,7 +557,7 @@ public int getMyAccessibleProjectsCount(User user) {
}
keys[keys.length - 2] = user.getEmail();
keys[keys.length - 1] = "everyone";
if (PermissionUtils.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) {
if (SW360Constants.IS_ADMIN_PRIVATE_ACCESS_ENABLED && isAdmin) {
return getConnector().getDocumentCount(Project.class);
}
if (isClearingAdmin) {
Expand Down Expand Up @@ -586,7 +587,7 @@ public ProjectData searchByType(String type, User user) {
Set<Project> accessibleProjects = filterAccessibleProjectsByIds(user, searchIds);
return getProjectData(accessibleProjects);
}

private ProjectData getProjectData(Set<Project> accessibleProjects) {
int totalSize = accessibleProjects.size();
ProjectData projectData = new ProjectData();
Expand Down
Loading
Loading