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

org.apache.chemistry.opencmis.client.runtime.QueryResultImpl Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.chemistry.opencmis.client.runtime;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ObjectFactory;
import org.apache.chemistry.opencmis.client.api.QueryResult;
import org.apache.chemistry.opencmis.client.api.Relationship;
import org.apache.chemistry.opencmis.client.api.Rendition;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.commons.data.AllowableActions;
import org.apache.chemistry.opencmis.commons.data.ObjectData;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.data.RenditionData;

/**
 * Implementation of QueryResult.
 */
public class QueryResultImpl implements QueryResult, Serializable {

    private static final long serialVersionUID = 1L;

    private Map> propertiesById;
    private Map> propertiesByQueryName;
    private AllowableActions allowableActions;
    private List relationships;
    private List renditions;

    /**
     * Constructor.
     */
    public QueryResultImpl(Session session, ObjectData objectData) {
        propertiesById = new LinkedHashMap>();
        propertiesByQueryName = new LinkedHashMap>();

        if (objectData != null) {

            ObjectFactory of = session.getObjectFactory();

            // handle properties
            if (objectData.getProperties() != null) {
                List> queryProperties = of.convertQueryProperties(objectData.getProperties());

                for (PropertyData property : queryProperties) {
                    propertiesById.put(property.getId(), property);
                    propertiesByQueryName.put(property.getQueryName(), property);
                }
            }

            // handle allowable actions
            if (objectData.getAllowableActions() != null) {
                this.allowableActions = objectData.getAllowableActions();
            }

            // handle relationships
            if (objectData.getRelationships() != null) {
                relationships = new ArrayList();
                for (ObjectData rod : objectData.getRelationships()) {
                    CmisObject relationship = of.convertObject(rod, session.getDefaultContext());
                    if (relationship instanceof Relationship) {
                        relationships.add((Relationship) relationship);
                    }
                }
            }

            // handle renditions
            if (objectData.getRenditions() != null) {
                this.renditions = new ArrayList();
                for (RenditionData rd : objectData.getRenditions()) {
                    this.renditions.add(of.convertRendition(null, rd));
                }
            }
        }
    }

    @Override
    public List> getProperties() {
        return new ArrayList>(propertiesByQueryName.values());
    }

    @Override
    @SuppressWarnings("unchecked")
    public  PropertyData getPropertyById(String id) {
        return (PropertyData) propertiesById.get(id);
    }

    @Override
    @SuppressWarnings("unchecked")
    public  PropertyData getPropertyByQueryName(String queryName) {
        return (PropertyData) propertiesByQueryName.get(queryName);
    }

    @Override
    public  T getPropertyValueById(String id) {
        PropertyData property = getPropertyById(id);
        if (property == null) {
            return null;
        }

        return property.getFirstValue();
    }

    @Override
    public  T getPropertyValueByQueryName(String queryName) {
        PropertyData property = getPropertyByQueryName(queryName);
        if (property == null) {
            return null;
        }

        return property.getFirstValue();
    }

    @Override
    public  List getPropertyMultivalueById(String id) {
        PropertyData property = getPropertyById(id);
        if (property == null) {
            return null;
        }

        return property.getValues();
    }

    @Override
    public  List getPropertyMultivalueByQueryName(String queryName) {
        PropertyData property = getPropertyByQueryName(queryName);
        if (property == null) {
            return null;
        }

        return property.getValues();
    }

    @Override
    public AllowableActions getAllowableActions() {
        return allowableActions;
    }

    @Override
    public List getRelationships() {
        return relationships;
    }

    @Override
    public List getRenditions() {
        return renditions;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy