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

org.eclipse.dirigible.components.odata.service.ODataMetadataService Maven / Gradle / Ivy

There is a newer version: 10.6.37
Show newest version
/*
 * Copyright (c) 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 *
 * SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and Eclipse Dirigible contributors
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.dirigible.components.odata.service;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

import org.apache.olingo.odata2.api.exception.ODataException;
import org.eclipse.dirigible.components.odata.domain.ODataContainer;
import org.eclipse.dirigible.components.odata.domain.ODataSchema;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * The Class ODataMetadataService.
 */
@Service
public class ODataMetadataService implements InitializingBean {
	
	/** The instance. */
	private static ODataMetadataService INSTANCE;
	
	/**
	 * After properties set.
	 *
	 * @throws Exception the exception
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		INSTANCE = this;		
	}
	
	/**
	 * Gets the.
	 *
	 * @return the o data metadata service
	 */
	public static ODataMetadataService get() {
        return INSTANCE;
    }
	
	/**
	 * Gets the o data container service.
	 *
	 * @return the o data container service
	 */
	public ODataContainerService getODataContainerService() {
		return ODataContainerService.get();
	}
	
	/**
	 * Gets the o data schema service.
	 *
	 * @return the o data schema service
	 */
	public ODataSchemaService getODataSchemaService() {
		return ODataSchemaService.get();
	}
	
	/**
     * Gets the metadata.
     *
     * @return the metadata
     * @throws ODataException the o data exception
     */
    public InputStream getMetadata() throws ODataException {
        StringBuilder builder = new StringBuilder();
        builder.append("\n");
        builder.append("\n");
        builder.append("    \n");

        List schemas = getODataSchemaService().getAll();
        for (ODataSchema schema : schemas) {
            builder.append(new String(schema.getContent()));
            builder.append("\n");
        }

        builder.append("\n");
        builder.append("    \n");
        List containers = getODataContainerService().getAll();
        for (ODataContainer container : containers) {
            builder.append(new String(container.getContent()));
            builder.append("\n");
        }
        builder.append("    \n");
        builder.append("\n");

        builder.append("    \n");
        builder.append("\n");

        return new ByteArrayInputStream(builder.toString().getBytes());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy