Skip to content

Commit

Permalink
fix(m360-api): decouple components to external lib
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv committed Aug 28, 2023
1 parent 6576610 commit 8e45998
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 252 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
--set-env-vars FPI_DLR_WEBHOOK_KEY=${{ secrets.FPI_DLR_WEBHOOK_KEY }}
--set-env-vars FPI_GEN_WEBHOOK_KEY=${{ secrets.FPI_GEN_WEBHOOK_KEY }}
--set-env-vars FPI_APP_TO_APP_PASSW=${{ secrets.FPI_APP_TO_APP_PASSW }}
--set-env-vars M360_API_URL=${{ secrets.M360_API_URL }}
--set-env-vars DB_NAME=sms-api-dev
--cpu ${{ env.SERVICE_CPU }}
--memory ${{ env.SERVICE_MEMORY }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ jobs:
--set-env-vars FPI_DLR_WEBHOOK_KEY=${{ secrets.FPI_DLR_WEBHOOK_KEY }}
--set-env-vars FPI_GEN_WEBHOOK_KEY=${{ secrets.FPI_GEN_WEBHOOK_KEY }}
--set-env-vars FPI_APP_TO_APP_PASSW=${{ secrets.FPI_APP_TO_APP_PASSW }}
--set-env-vars M360_API_URL=${{ secrets.M360_API_URL }}
--set-env-vars DB_NAME=sms-api-prod
--cpu ${{ env.SERVICE_CPU }}
--memory ${{ env.SERVICE_MEMORY }}
Expand Down
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<artifactId>fpi-telco-plugin</artifactId>
</dependency>

<dependency>
<groupId>com.vincejv</groupId>
<artifactId>m360-api-client</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2023 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.sms.beanloader;

import com.abavilla.fpi.sms.rest.m360.M360ApiKeys;
import com.vincejv.m360.M360ApiClient;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;

/**
* Bean definition for {@link M360ApiClient}.
*
* @author <a href="mailto:vincevillamora@gmail.com">Vince Villamora</a>
*/
@ApplicationScoped
public class M360ApiLoader {

@Inject
M360ApiKeys keys;

@ConfigProperty(name = "ph.com.m360.base-url")
String baseUrl;

/**
* Creates a {@link M360ApiClient} instance using the default configurations
*
* @return {@link M360ApiClient} instance
*/
@Produces
M360ApiClient m360ApiClient() {
return new M360ApiClient(baseUrl, keys.getApiKey(), keys.getApiSecret(), keys.getSenderId());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2023 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.sms.codec;

import java.util.List;

import com.vincejv.m360.dto.BroadcastRequest;
import com.vincejv.m360.dto.IApiRequest;
import com.vincejv.m360.dto.SMSRequest;
import org.bson.codecs.Codec;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.codecs.pojo.ClassModel;
import org.bson.codecs.pojo.PojoCodecProvider;

/**
* MongoDB Codec registry, contains the codec for saving DVS API Objects to mongodb.
*
* @author <a href="mailto:vincevillamora@gmail.com">Vince Villamora</a>
*/
public class M360CodecProvider implements CodecProvider {

@SuppressWarnings("rawtypes")
private static final List<Class> discriminatorClasses;

static {
discriminatorClasses = List.of(
IApiRequest.class, BroadcastRequest.class, SMSRequest.class
);
}

@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
if (discriminatorClasses.contains(clazz)) {
return buildDiscriminatorCodec(clazz, registry);
}
return null; // Don't throw here, this tells
}

private static <T> Codec<T> buildDiscriminatorCodec(Class<T> clazz, CodecRegistry registry) {
ClassModel<T> discriminatorModel = ClassModel.builder(clazz)
.enableDiscriminator(true).build();
return PojoCodecProvider.builder()
.register(discriminatorModel)
.build().get(clazz, registry);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import com.abavilla.fpi.fw.dto.AbsDto;
import com.vincejv.m360.dto.IApiRequest;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -40,5 +41,5 @@ public class BroadcastResponseDto extends AbsDto {
private Integer telcoId;
private String messageId;
private List<String> message;
private BroadcastRequestDto broadcastRequest;
private IApiRequest broadcastRequest;
}

This file was deleted.

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

import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
import com.abavilla.fpi.telco.ext.enums.Telco;
import com.vincejv.m360.dto.IApiRequest;
import io.quarkus.mongodb.panache.common.MongoEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -47,6 +48,7 @@ public class MsgReq extends AbsMongoItem {
private Telco telco;
private String messageId;
private List<StateEncap> apiStatus;
private List<String> message;
@BsonProperty("request")
private BroadcastRequest broadcastRequest;
private IApiRequest broadcastRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
import com.abavilla.fpi.fw.mapper.IMapper;
import com.abavilla.fpi.fw.util.DateUtil;
import com.abavilla.fpi.sms.dto.api.m360.BroadcastResponseDto;
import com.abavilla.fpi.sms.dto.api.m360.M360ResponseDto;
import com.abavilla.fpi.sms.util.M360Const;
import com.vincejv.m360.dto.BroadcastResponse;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;

@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface BroadcastResponseMapper extends IMapper {
BroadcastResponseDto mapApiToDto(M360ResponseDto apiResponse);

BroadcastResponseDto mapApiToDto(BroadcastResponse apiResponse);

default LocalDateTime parseTimestamp(String timestamp) {
return DateUtil.modLdtToUtc(DateUtil.parseStrDateToLdt(timestamp, M360Const.M360_TIMESTAMP_FORMAT));
Expand Down

This file was deleted.

Loading

0 comments on commit 8e45998

Please sign in to comment.