Page MenuHomec4science

URLParserMaterial.java
No OneTemporary

File Metadata

Created
Tue, Jan 7, 00:03

URLParserMaterial.java

package io.serializer.url;
import io.serializer.ParserNamespace;
import java.util.LinkedList;
import utils.StringUtils;
import framework.MarkerEncrypted;
import framework.request.RequestMaterial;
public class URLParserMaterial extends URLParser {
public static String requestToString(RequestMaterial request) {
StringBuilder sb = new StringBuilder();
sb.append(ParserNamespace.CNAME_PATIENT).append(QUERY_ASSIGN);
sb.append(Integer.toString(request.getPatientId()));
sb.append(QUERY_AND);
sb.append(ParserNamespace.CNAME_MARKER_ID_LIST).append(QUERY_ASSIGN);
sb.append(StringUtils.join(SEP_EXT, request.getRequiredMarkers()));
sb.append(QUERY_AND);
sb.append(ParserNamespace.CNAME_CF_ID_LIST).append(QUERY_ASSIGN);
sb.append(StringUtils.join(SEP_EXT, request.getRequiredCFs()));
return sb.toString();
}
public static RequestMaterial stringToRequest(String requestString) {
String[] parts = requestString.split(QUERY_AND);
int patientId = extractPatientId(parts[0]);
LinkedList<MarkerEncrypted> markers = extractMarkerId(parts[1]);
LinkedList<MarkerEncrypted> cfs = extractCFId(parts[2]);
RequestMaterial request = new RequestMaterial(markers, cfs, patientId);
return request;
}
private static LinkedList<MarkerEncrypted> extractMarkerId(String val) {
String markersConcat = extractVal(val, ParserNamespace.CNAME_MARKER_ID_LIST);
LinkedList<MarkerEncrypted> markers = new LinkedList<>();
String[] markersString = markersConcat.split(SEP_EXT);
for (String marker : markersString) {
markers.add(new MarkerEncrypted(marker));
}
return markers;
}
private static LinkedList<MarkerEncrypted> extractCFId(String val) {
String cfsConcat = extractVal(val, ParserNamespace.CNAME_CF_ID_LIST);
LinkedList<MarkerEncrypted> cfs = new LinkedList<>();
String[] cfsString = cfsConcat.split(SEP_EXT);
for (String cf : cfsString) {
cfs.add(new MarkerEncrypted(cf));
}
return cfs;
}
}

Event Timeline