All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.uid2.shared.store.parser.ServiceParser Maven / Gradle / Ivy

package com.uid2.shared.store.parser;

import com.uid2.shared.Utils;
import com.uid2.shared.auth.Role;
import com.uid2.shared.model.Service;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class ServiceParser implements Parser> {

    @Override
    public ParsingResult> deserialize(InputStream inputStream) throws IOException {
        JsonArray spec = Utils.toJsonArray(inputStream);
        final HashMap serviceMap = new HashMap<>();
        for (int i = 0; i < spec.size(); i++) {
            JsonObject serviceSpec = spec.getJsonObject(i);
            int serviceId = serviceSpec.getInteger("service_id");
            int siteId = serviceSpec.getInteger("site_id");
            String name = serviceSpec.getString("name");
            JsonArray rolesSpec = serviceSpec.getJsonArray("roles");

            HashSet roles = new HashSet<>();
            for (int j = 0; j < rolesSpec.size(); j++) {
                roles.add(Enum.valueOf(Role.class, rolesSpec.getString(j)));
            }

            Service service = new Service(serviceId, siteId, name, roles);

            serviceMap.put(serviceId, service);
        }
        return new ParsingResult<>(serviceMap, serviceMap.size());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy