Skip to content

Commit

Permalink
Merge branch 'develop' into feature/orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Nov 26, 2024
2 parents a072e00 + afdd80f commit 09f4af5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package com.epam.ta.reportportal.commons.querygen;

import com.epam.reportportal.rules.exception.ErrorType;
import static com.epam.reportportal.rules.commons.validation.Suppliers.formattedSupplier;

import com.epam.reportportal.rules.commons.validation.BusinessRule;
import com.epam.reportportal.rules.commons.validation.Suppliers;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.commons.querygen.query.JoinEntity;
import com.epam.ta.reportportal.entity.enums.IntegrationGroupEnum;
import com.epam.ta.reportportal.entity.enums.LaunchModeEnum;
import com.epam.ta.reportportal.entity.enums.LogLevel;
import com.epam.ta.reportportal.entity.enums.StatusEnum;
import com.epam.ta.reportportal.entity.enums.TestItemIssueGroup;
import com.epam.ta.reportportal.entity.enums.TestItemTypeEnum;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.jooq.enums.JIntegrationGroupEnum;
import com.epam.ta.reportportal.jooq.enums.JLaunchModeEnum;
import com.epam.ta.reportportal.jooq.enums.JStatusEnum;
Expand All @@ -41,6 +42,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import org.apache.commons.lang3.BooleanUtils;
import org.jooq.Field;
import org.jooq.impl.DSL;
Expand Down Expand Up @@ -165,7 +167,7 @@ public Object castValue(String oneValue, ErrorType errorType) {
castedValue = DateTimeUtils.parseDateTimeWithOffset(oneValue);
} catch (DateTimeParseException e) {
throw new ReportPortalException(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid date", oneValue).get()
formattedSupplier("Cannot convert '{}' to valid date", oneValue).get()
);
}
}
Expand All @@ -176,25 +178,25 @@ public Object castValue(String oneValue, ErrorType errorType) {
Optional<LogLevel> level = LogLevel.toLevel(oneValue);
BusinessRule.expect(level, Optional::isPresent)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'LogLevel'", oneValue));
formattedSupplier("Cannot convert '{}' to valid 'LogLevel'", oneValue));
castedValue = level.get().toInt();
BusinessRule.expect(castedValue, Objects::nonNull)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'LogLevel'", oneValue));
formattedSupplier("Cannot convert '{}' to valid 'LogLevel'", oneValue));
} else if (JStatusEnum.class.isAssignableFrom(getDataType())) {

Optional<StatusEnum> status = StatusEnum.fromValue(oneValue);
BusinessRule.expect(status, Optional::isPresent)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Status'", oneValue));
formattedSupplier("Cannot convert '{}' to valid 'Status'", oneValue));
castedValue = JStatusEnum.valueOf(status.get().name());

} else if (JTestItemTypeEnum.class.isAssignableFrom(getDataType())) {

Optional<TestItemTypeEnum> itemType = TestItemTypeEnum.fromValue(oneValue);
BusinessRule.expect(itemType, Optional::isPresent)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Test item type'",
formattedSupplier("Cannot convert '{}' to valid 'Test item type'",
oneValue));
castedValue = JTestItemTypeEnum.valueOf(itemType.get().name());

Expand All @@ -203,28 +205,35 @@ public Object castValue(String oneValue, ErrorType errorType) {
Optional<LaunchModeEnum> launchMode = LaunchModeEnum.findByName(oneValue);
BusinessRule.expect(launchMode, Optional::isPresent)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Launch mode'", oneValue));
formattedSupplier("Cannot convert '{}' to valid 'Launch mode'", oneValue));
castedValue = JLaunchModeEnum.valueOf(launchMode.get().name());

} else if (JIntegrationGroupEnum.class.isAssignableFrom(getDataType())) {

Optional<IntegrationGroupEnum> integrationGroup = IntegrationGroupEnum.findByName(oneValue);
BusinessRule.expect(integrationGroup, Optional::isPresent)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Integration group",
formattedSupplier("Cannot convert '{}' to valid 'Integration group",
oneValue));
castedValue = JIntegrationGroupEnum.valueOf(integrationGroup.get().name());

} else if (TestItemIssueGroup.class.isAssignableFrom(getDataType())) {
castedValue = TestItemIssueGroup.validate(oneValue);
BusinessRule.expect(castedValue, Objects::nonNull)
.verify(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid 'Issue Type'", oneValue));
formattedSupplier("Cannot convert '{}' to valid 'Issue Type'", oneValue));
} else if (Collection.class.isAssignableFrom(getDataType())) {
/* Collection doesn't stores objects as ObjectId */
castedValue = oneValue;
} else if (String.class.isAssignableFrom(getDataType())) {
castedValue = oneValue != null ? oneValue.trim() : null;
} else if (UUID.class.isAssignableFrom(getDataType())) {
try {
castedValue = UUID.fromString(oneValue);
} catch (IllegalArgumentException e) {
throw new ReportPortalException(errorType,
formattedSupplier("Cannot convert '{}' to valid 'UUID'", oneValue));
}
} else {
castedValue = DSL.val(oneValue).cast(getDataType());
}
Expand All @@ -237,7 +246,7 @@ private Long parseLong(String value, ErrorType errorType) {
return Long.parseLong(value);
} catch (final NumberFormatException nfe) {
throw new ReportPortalException(errorType,
Suppliers.formattedSupplier("Cannot convert '{}' to valid number", value));
formattedSupplier("Cannot convert '{}' to valid number", value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ Page<User> findAllByUserTypeAndExpired(@Param("userType") UserType userType,

/**
* Updates user's last login value
*
* @param lastLogin Last login date
* @param username User
*/
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE users SET metadata = jsonb_set(metadata, '{metadata,last_login}', to_jsonb(extract(EPOCH FROM CAST (:lastLogin AS TIMESTAMP)) * 1000), TRUE ) WHERE login = :username", nativeQuery = true)
void updateLastLoginDate(@Param("lastLogin") Instant lastLogin,
@Param("username") String username);
@Query(value = "UPDATE users SET metadata = jsonb_set(metadata, '{metadata,last_login}', to_jsonb(round(extract(EPOCH from clock_timestamp()) * 1000)), TRUE ) WHERE login = :username", nativeQuery = true)
void updateLastLoginDate(@Param("username") String username);

@Query(value = "SELECT u.login FROM users u JOIN project_user pu ON u.id = pu.user_id WHERE pu.project_id = :projectId", nativeQuery = true)
List<String> findNamesByProject(@Param("projectId") Long projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public enum ActivityAction {
CREATE_PROJECT("createProject"),
DELETE_PROJECT("deleteProject"),
BULK_DELETE_PROJECT("bulkDeleteProject"),
UPDATE_PATTERN_ANALYZER("updatePatternAnalysisSettings");
UPDATE_PATTERN_ANALYZER("updatePatternAnalysisSettings"),

UPDATE_INSTANCE("updateInstance");

private final String value;

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

public enum EventObject {

INSTANCE("instance"),
LAUNCH("launch"),
DASHBOARD("dashboard"),
DEFECT_TYPE("defectType"),
Expand Down

0 comments on commit 09f4af5

Please sign in to comment.