Skip to content

Commit

Permalink
feat: Remove Useless database table / Update UT - MEED-7589 - Meeds-i…
Browse files Browse the repository at this point in the history
  • Loading branch information
AzmiTouil committed Oct 9, 2024
1 parent 774c236 commit 170a122
Show file tree
Hide file tree
Showing 55 changed files with 1,073 additions and 695 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public class DistributionForecast {

private double acceptedContributions;

private double Budget;
private double budget;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class RewardSettings implements Serializable, Cloneable {

private String timeZone = ZoneId.systemDefault().getId();

private RewardBudgetType budgetType = RewardBudgetType.DEFAULT;;
private RewardBudgetType budgetType = RewardBudgetType.DEFAULT;

private double threshold = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public interface RewardReportService {
* @param localDate a {@link LocalDate} inside the period time
* that will be retrieved
* @param username current username sending rewards
* @throws Exception if an error occurs while sending the rewards transactions
* @throws IllegalAccessException if an error occurs while sending the rewards transactions
* on blockchain
*/
void sendRewards(LocalDate localDate, String username) throws Exception; // NOSONAR
void sendRewards(LocalDate localDate, String username) throws IllegalAccessException; // NOSONAR

/**
* Retrieve a {@link RewardReport} corresponding to a period of time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public interface WalletTokenAdminService {
* @param address
* @return {@link TransactionDetail} with the hash of the transaction sent in
* blockchain
* @throws Exception
*/
BigInteger getTokenBalanceOf(String address) throws Exception;// NOSONAR
BigInteger getTokenBalanceOf(String address);// NOSONAR

/**
* Get ether balance of a wallet address (on blockchain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.List;
import java.util.Locale;

import org.springframework.stereotype.Service;

import io.meeds.wallet.model.TransactionDetail;
import io.meeds.wallet.model.TransactionStatistics;
import io.meeds.wallet.model.Wallet;
Expand All @@ -37,7 +35,7 @@ public interface WalletTransactionService {
* @param address {@link Wallet} address
* @return {@link List} of pending {@link TransactionDetail}
*/
public List<TransactionDetail> getPendingWalletTransactionsNotSent(String address);
List<TransactionDetail> getPendingWalletTransactionsNotSent(String address);

/**
* Retrieves the list of pending transactions of a given wallet from database
Expand All @@ -46,14 +44,14 @@ public interface WalletTransactionService {
* @param address {@link Wallet} address
* @return {@link List} of pending {@link TransactionDetail}
*/
public List<TransactionDetail> getPendingWalletTransactionsSent(String address);
List<TransactionDetail> getPendingWalletTransactionsSent(String address);

/**
* @param address {@link Wallet} address
* @return {@link List} of pending {@link TransactionDetail} of type ether
* sending marked as pending in database
*/
public List<TransactionDetail> getPendingEtherTransactions(String address);
List<TransactionDetail> getPendingEtherTransactions(String address);

/**
* @return pending contract transactions already sent to blockchain
Expand Down Expand Up @@ -207,7 +205,7 @@ List<TransactionDetail> getTransactions(String address, // NOSONAR
* @param transactionDetail of type {@link TransactionDetail} that boosted a
* previous {@link TransactionDetail} having the same nonce
*/
public void cancelTransactionsWithSameNonce(TransactionDetail transactionDetail);
void cancelTransactionsWithSameNonce(TransactionDetail transactionDetail);

/**
* Count the number of transactions sent from the same Wallet and having same
Expand All @@ -219,11 +217,11 @@ List<TransactionDetail> getTransactions(String address, // NOSONAR
* @return {@link Long} for transactions having same nonce but the designated
* transactionHash
*/
public long countPendingTransactionsWithSameNonce(String transactionHash, String fromAddress, long nonce);
long countPendingTransactionsWithSameNonce(String transactionHash, String fromAddress, long nonce);

/**
* @return count of transactions present in database
*/
public long countTransactions();
long countTransactions();

}
2 changes: 1 addition & 1 deletion wallet-reward-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
<artifactId>wallet-reward-services</artifactId>
<name>Meeds:: Add-on:: Wallet - Reward Services</name>
<properties>
<exo.test.coverage.ratio>0.18</exo.test.coverage.ratio>
<exo.test.coverage.ratio>0.83</exo.test.coverage.ratio>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;

import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

import io.meeds.wallet.reward.service.RewardReportService;
import io.meeds.wallet.reward.service.RewardSettingsService;
Expand All @@ -59,21 +53,19 @@
import org.springframework.data.web.PagedResourcesAssembler;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.PagedModel;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;


@RestController
@RequestMapping("reward")
@Tag(name = "rewards", description = "Manage wallet rewards") // NOSONAR
public class RewardReportREST {

private static final String ERROR_PARAM = "error";

private static final String ERROR_EMPTY_PARAM_DATE = "Bad request sent to server with empty 'date' parameter";

private static final Log LOG = ExoLogger.getLogger(RewardReportREST.class);

@Autowired
private RewardReportService rewardReportService;

Expand Down Expand Up @@ -160,23 +152,13 @@ public Response computeRewardsByUser(@Parameter(description = "A date with forma
@RequestParam("date")
String date) {
if (StringUtils.isBlank(date)) {
return Response.status(HTTPStatus.BAD_REQUEST).entity(ERROR_EMPTY_PARAM_DATE).build();
}
try {
RewardPeriod rewardPeriod = getRewardPeriod(date);
RewardReport rewardReport = rewardReportService.computeRewardsByUser(rewardPeriod.getPeriodMedianDate(), WalletUtils.getCurrentUserIdentityId());
rewardReport.setPeriod(new RewardPeriodWithFullDate(rewardReport.getPeriod()));
return Response.ok(rewardReport).build();
} catch (Exception e) {
LOG.error("Error getting user's computed reward", e);
JSONObject object = new JSONObject();
try {
object.append(ERROR_PARAM, e.getMessage());
} catch (JSONException e1) {
// Nothing to do
}
return Response.status(HTTPStatus.INTERNAL_ERROR).type(MediaType.APPLICATION_JSON).entity(object.toString()).build();
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, ERROR_EMPTY_PARAM_DATE);
}
RewardPeriod rewardPeriod = getRewardPeriod(date);
RewardReport rewardReport = rewardReportService.computeRewardsByUser(rewardPeriod.getPeriodMedianDate(),
WalletUtils.getCurrentUserIdentityId());
rewardReport.setPeriod(new RewardPeriodWithFullDate(rewardReport.getPeriod()));
return Response.ok(rewardReport).build();
}


Expand All @@ -191,21 +173,13 @@ public Response computeRewardsByUser(@Parameter(description = "A date with forma
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "401", description = "Unauthorized operation"),
@ApiResponse(responseCode = "500", description = "Internal server error") })
public Response sendRewards(HttpServletRequest request,
@RequestBody
RewardPeriod rewardPeriod) {
public void sendRewards(HttpServletRequest request,
@RequestBody
RewardPeriod rewardPeriod) {
try {
rewardReportService.sendRewards(rewardPeriod.getPeriodMedianDate(), request.getRemoteUser());
return Response.noContent().build();
} catch (Exception e) {
LOG.error("Error getting computed reward", e);
JSONObject object = new JSONObject();
try {
object.append(ERROR_PARAM, e.getMessage());
} catch (JSONException e1) {
// Nothing to do
}
return Response.status(HTTPStatus.INTERNAL_ERROR).type(MediaType.APPLICATION_JSON).entity(object.toString()).build();
} catch (IllegalAccessException e) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
}
}

Expand All @@ -222,20 +196,9 @@ public Response sendRewards(HttpServletRequest request,
public Response listRewards(@Parameter(description = "limit of items to load", required = true)
@RequestParam("limit")
int limit) {
try {
List<WalletReward> rewards = rewardReportService.listRewards(WalletUtils.getCurrentUserId(), limit);
rewards.forEach(reward -> reward.setPeriod(new RewardPeriodWithFullDate(reward.getPeriod())));
return Response.ok(rewards).build();
} catch (Exception e) {
LOG.error("Error getting list of reward for current user", e);
JSONObject object = new JSONObject();
try {
object.append(ERROR_PARAM, e.getMessage());
} catch (JSONException e1) {
// Nothing to do
}
return Response.status(HTTPStatus.INTERNAL_ERROR).type(MediaType.APPLICATION_JSON).entity(object.toString()).build();
}
List<WalletReward> rewards = rewardReportService.listRewards(WalletUtils.getCurrentUserId(), limit);
rewards.forEach(reward -> reward.setPeriod(new RewardPeriodWithFullDate(reward.getPeriod())));
return Response.ok(rewards).build();
}

@GetMapping(path = "countRewards")
Expand All @@ -248,31 +211,18 @@ public Response listRewards(@Parameter(description = "limit of items to load", r
@ApiResponse(responseCode = "200", description = "Request fulfilled"),
@ApiResponse(responseCode = "401", description = "Unauthorized operation"),
@ApiResponse(responseCode = "500", description = "Internal server error") })
public Response countRewards(@Context Request request,
@Parameter(description = "user id", required = true)
@RequestParam("userId")
String userId) {
try {
Double sumRewards = rewardReportService.countRewards(userId);
EntityTag eTag = new EntityTag(String.valueOf(sumRewards));
Response.ResponseBuilder builder = request.evaluatePreconditions(eTag);
if (builder == null) {
JSONObject result = new JSONObject();
result.put("sumRewards", sumRewards);
builder = Response.ok(result.toString(), MediaType.APPLICATION_JSON);
builder.tag(eTag);
}
return builder.build();
} catch (Exception e) {
LOG.error("Error getting sum of reward for current user", e);
JSONObject object = new JSONObject();
try {
object.append(ERROR_PARAM, e.getMessage());
} catch (JSONException e1) {
// Nothing to do
}
return Response.status(HTTPStatus.INTERNAL_ERROR).type(MediaType.APPLICATION_JSON).entity(object.toString()).build();
public ResponseEntity<Double> countRewards(HttpServletRequest request,
@Parameter(description = "user id", required = true)
@RequestParam("userId")
String userId) {
Double sumRewards = rewardReportService.countRewards(userId);
String eTagValue = String.valueOf(sumRewards.hashCode());

String requestETag = request.getHeader(HttpHeaders.IF_NONE_MATCH);
if (requestETag != null && requestETag.equals(eTagValue)) {
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).build();
}
return ResponseEntity.ok().eTag(eTagValue).body(sumRewards);
}

@GetMapping(path = "periods")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import javax.ws.rs.core.Response;
import org.apache.commons.lang3.StringUtils;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;

import io.meeds.wallet.model.RewardPeriod;
import io.meeds.wallet.model.RewardPeriodType;
Expand All @@ -47,8 +45,6 @@
@Tag(name = "reward/settings", description = "Manage reward module settings") // NOSONAR
public class RewardSettingsREST {

private static final Log LOG = ExoLogger.getLogger(RewardSettingsREST.class);

@Autowired
private RewardSettingsService rewardSettingsService;

Expand Down Expand Up @@ -77,14 +73,9 @@ public RewardSettings getSettings() {
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "401", description = "Unauthorized operation"),
@ApiResponse(responseCode = "500", description = "Internal server error") })
public Response saveSettings(@RequestBody
RewardSettings rewardSettings) {
try {
rewardSettingsService.saveSettings(rewardSettings);
return Response.noContent().build();
} catch (IllegalArgumentException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
public void saveSettings(@RequestBody
RewardSettings rewardSettings) {
rewardSettingsService.saveSettings(rewardSettings);
}

@DeleteMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public WalletRewardReportService(WalletAccountService walletAccountService,
}

@Override
public void sendRewards(LocalDate date, String username) throws Exception { // NOSONAR
public void sendRewards(LocalDate date, String username) throws IllegalAccessException { // NOSONAR
if (!isUserRewardingAdmin(username)) {
throw new IllegalAccessException("User " + username + " is not allowed to send rewards");
}
Expand Down Expand Up @@ -463,13 +463,8 @@ private void computeReward(RewardSettings rewardSettings, Map<Long, Double> earn
// Filter non-eligible users switch threshold
filterEligibleMembers(earnedPoints.entrySet(), enabledRewards, rewardSettings);

double amountPerPoint;
double totalFixedBudget;
switch (budgetType) {
case FIXED_PER_POINT:
amountPerPoint = configuredPluginAmount;
addRewardsSwitchPointAmount(enabledRewards, earnedPoints.entrySet(), amountPerPoint);
break;
case FIXED:
totalFixedBudget = configuredPluginAmount;
addTeamMembersReward(earnedPoints, totalFixedBudget, enabledRewards);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,24 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

</changeSet>

<changeSet id="reward" author="1.0.0-17">
<preConditions>
<tableExists tableName="ADDONS_WALLET_GAM_TEAM"/>
<tableExists tableName="ADDONS_WALLET_GAM_TEAM_MEMBER"/>
<tableExists tableName="ADDONS_WALLET_REWARD_PLUGIN"/>
<foreignKeyConstraintExists foreignKeyTableName="ADDONS_WALLET_GAM_TEAM_MEMBER"
foreignKeyName="FK_WALLET_GAM_01"/>
<foreignKeyConstraintExists foreignKeyTableName="ADDONS_WALLET_REWARD" foreignKeyName="FK_WALLET_GAM_02"/>
</preConditions>
<dropForeignKeyConstraint
baseTableName="ADDONS_WALLET_GAM_TEAM_MEMBER"
constraintName="FK_WALLET_GAM_01"/>
<dropForeignKeyConstraint
baseTableName="ADDONS_WALLET_REWARD"
constraintName="FK_WALLET_GAM_02"/>
<dropTable tableName="ADDONS_WALLET_GAM_TEAM"/>
<dropTable tableName="ADDONS_WALLET_GAM_TEAM_MEMBER"/>
<dropTable tableName="ADDONS_WALLET_REWARD_PLUGIN"/>
</changeSet>

</databaseChangeLog>
Loading

0 comments on commit 170a122

Please sign in to comment.