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

fix(m360-api): api rework #129

Merged
merged 1 commit into from
Aug 31, 2023
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
76 changes: 71 additions & 5 deletions core/src/main/java/com/abavilla/fpi/sms/codec/DCSCodingCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,83 @@

package com.abavilla.fpi.sms.codec;

import com.abavilla.fpi.fw.codec.AbsEnumCodec;
import com.abavilla.fpi.sms.entity.enums.DCSCoding;
import java.lang.reflect.Method;

public class DCSCodingCodec extends AbsEnumCodec<DCSCoding> {
import com.vincejv.m360.dto.DCSCoding;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.bson.BsonReader;
import org.bson.BsonType;
import org.bson.BsonWriter;
import org.bson.codecs.Codec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;

public DCSCodingCodec() {
super();
/**
* Codec for encoding and decoding {@link DCSCoding} enum to MongoDB Document
*
* @author <a href="mailto:[email protected]">Vince Villamora</a>
*/
@NoArgsConstructor
public class DCSCodingCodec implements Codec<DCSCoding> {

/**
* Document key name for the value node
*/
public static final String VALUE_KEY_NODE_NAME = "value";

/**
* Document key name for the enum id
*/
public static final String ORD_KEY_NODE_NAME = "ord";

/**
* {@inheritDoc}
*/
@SneakyThrows
@Override
public DCSCoding decode(BsonReader reader, DecoderContext decoderContext) {
reader.readStartDocument();
int ord = Integer.MIN_VALUE;
while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) {
// decode only value type, ignore ord
String key = reader.readName();
if (StringUtils.equals(key, VALUE_KEY_NODE_NAME)) {
reader.readString();
} else if (StringUtils.equals(key, ORD_KEY_NODE_NAME)) {
ord = reader.readInt32();
} else {
reader.skipValue();
}
}
reader.readEndDocument();

Method fromValue = getEncoderClass().getDeclaredMethod("fromId", int.class);
return (DCSCoding) fromValue.invoke(null, ord);
}

/**
* {@inheritDoc}
*/
@SneakyThrows
@Override
public void encode(BsonWriter writer, DCSCoding value, EncoderContext encoderContext) {
if (value != null) {
Method getId = getEncoderClass().getDeclaredMethod("getId");
writer.writeStartDocument();
writer.writeString(VALUE_KEY_NODE_NAME, value.toString());
writer.writeInt32(ORD_KEY_NODE_NAME, (Integer) getId.invoke(value));
writer.writeEndDocument();
}
}

/**
* {@inheritDoc}
*/
@Override
public Class<DCSCoding> getEncoderClass() {
return DCSCoding.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package com.abavilla.fpi.sms.codec;

import com.abavilla.fpi.fw.codec.IEnumCodecProvider;
import com.abavilla.fpi.sms.entity.enums.DCSCoding;
import com.abavilla.fpi.telco.ext.codec.ApiStatusCodec;
import com.abavilla.fpi.telco.ext.codec.TelcoCodec;
import com.abavilla.fpi.telco.ext.enums.ApiStatus;
import com.abavilla.fpi.telco.ext.enums.Telco;
import com.vincejv.m360.dto.DCSCoding;
import org.bson.codecs.Codec;

public class EnumCodecProvider implements IEnumCodecProvider {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.vincejv.m360.dto.ApiResponse;
import com.vincejv.m360.dto.BroadcastRequest;
import com.vincejv.m360.dto.BroadcastResponse;
import com.vincejv.m360.dto.DCSCoding;
import com.vincejv.m360.dto.ErrorResponse;
import com.vincejv.m360.dto.PageInfo;
import com.vincejv.m360.dto.SMSRequest;
Expand All @@ -35,6 +36,7 @@
ApiResponse.class,
BroadcastRequest.class,
BroadcastResponse.class,
DCSCoding.class,
ErrorResponse.class,
PageInfo.class,
SMSRequest.class,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package com.abavilla.fpi.sms.entity.sms;

import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
import com.abavilla.fpi.sms.entity.enums.DCSCoding;
import com.abavilla.fpi.fw.entity.mongo.AbsMongoField;
import com.vincejv.m360.dto.DCSCoding;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.bson.codecs.pojo.annotations.BsonDiscriminator;
import org.bson.codecs.pojo.annotations.BsonProperty;

Expand All @@ -32,7 +33,8 @@
@RegisterForReflection
@AllArgsConstructor
@BsonDiscriminator
public class BroadcastRequest extends AbsMongoItem {
@NoArgsConstructor
public class BroadcastRequestEntity extends AbsMongoField {

@BsonProperty("msisdn")
private String mobileNumber;
Expand All @@ -49,7 +51,4 @@ public class BroadcastRequest extends AbsMongoItem {
@BsonProperty("dcs")
private DCSCoding dataCodingScheme;

public BroadcastRequest() {
isInternational = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.time.LocalDateTime;
import java.util.List;

import com.abavilla.fpi.fw.entity.mongo.AbsMongoField;
import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
import com.abavilla.fpi.telco.ext.enums.Telco;
import com.vincejv.m360.dto.ApiRequest;
import io.quarkus.mongodb.panache.common.MongoEntity;
import io.quarkus.runtime.annotations.RegisterForReflection;
import lombok.Data;
Expand Down Expand Up @@ -52,5 +52,5 @@ public class MsgReq extends AbsMongoItem {
private List<StateEncap> apiStatus;
private List<String> message;
@BsonProperty(value = "request", useDiscriminator = true)
private ApiRequest broadcastRequest;
private AbsMongoField broadcastRequest;
}
Loading
Loading