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

rapture.common.dp.WorkOrderStorage Maven / Gradle / Ivy

There is a newer version: 3.0.4
Show newest version
/**
 * The MIT License (MIT)
 *
 * Copyright (C) 2011-2016 Incapture Technologies LLC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * This file is autogenerated and any changes will be overwritten.
 */

package rapture.common.dp;

import rapture.object.storage.StorageLocationFactory;

import rapture.common.RaptureFolderInfo;
import rapture.common.RaptureURI;
import rapture.common.TableQueryResult;
import rapture.object.storage.StorageLocationFactory;

import rapture.common.impl.jackson.JsonContent;
import rapture.object.storage.ObjectFilter;
import rapture.object.storage.ObjectStorage;
import rapture.persistence.storable.mapper.impl.jackson.StorableObjectMapper;
import rapture.repo.RepoVisitor;

import java.util.List;

import org.apache.log4j.Logger;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import rapture.common.impl.jackson.JacksonUtil;
import java.io.IOException;


import rapture.server.ServerApiVersion;

import rapture.common.version.OldestVersion;


@SuppressWarnings("all")
public class WorkOrderStorage {
    private static final Logger log = Logger.getLogger(WorkOrderStorage.class);
    private static final WorkOrderStorableInfo storableInfo = new WorkOrderStorableInfo();

    /**
     * Return a {@link WorkOrder} based on its member fields. This is useful if you know the value of
     * the member fields of the object, but not the exact storage location or address.
     * 
     * @return The {@link WorkOrder} object stored at this address
     */
    public static WorkOrder readByFields(String workOrderURI) {
        RaptureURI storageLocation 
          = new WorkOrderPathBuilder()
           .workOrderURI(workOrderURI)
    			        .buildStorageLocation();

            return ObjectStorage.read(storageLocation, WorkOrder.class, storableInfo, getObjectMapper());
    }

    /**
     * Get the folders or {@link WorkOrder} objects under parentFolderPath.
     * Searches the tree of objects of type {@link WorkOrder}
     * 
     * @param parentFolderPath
     * @return
     */
    public static List getChildren(String parentFolderPath) {
        return ObjectStorage.getChildren(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), storableInfo, parentFolderPath);
    }

    /**
     * Removes the documents and folders {@link WorkOrder} objects under parentFolderPath.
     * 
     * @param parentFolderPath
     * @return
     */
    public static List removeFolder(String parentFolderPath) {
        return ObjectStorage.removeFolder(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), storableInfo, parentFolderPath);
    }

    /**
     * Return all the {@link WorkOrder} objects currently stored in Rapture
     * @return
     */
    public static List readAll() {
        return ObjectStorage.readAll(WorkOrder.class, WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), storableInfo, "", getObjectMapper());
    }

    /**
     * Return all the {@link WorkOrder} objects currently stored in Rapture 
     * @param
     * filterPrefix The prefix of the storageLocation that you want to filter by
     * 
     * @return
     */
    public static List readAll(String filterPrefix) {
        return ObjectStorage.readAll(WorkOrder.class, WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), storableInfo, filterPrefix, getObjectMapper());
    }

    /**
     * Return all the {@link WorkOrder} objects currently stored in Rapture which match an ObjectFilter
     * @param
     * filterPrefix The prefix of the storageLocation that you want to filter by
     * @param
     * filter An ObjectFilter
     *
     * @return
     */
    public static List filterAll(ObjectFilter filter) {
        return ObjectStorage.filterAll(WorkOrder.class, WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), storableInfo, "", filter, getObjectMapper());
    }


    /**
     * Visit the repository storing {@link WorkOrder} objects
     * 
     * @param visitor
     */
    public static void visitAll(RepoVisitor visitor) {
        ObjectStorage.visitAll(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), "", storableInfo, visitor);
    }


    /**
     * Return a {@link WorkOrder} based on its storage location
     * 
     * @param storageLocationURI The storage location for this WorkOrder
     * @return The {@link WorkOrder} object stored at this address
     */
    public static WorkOrder readByStorageLocation(RaptureURI storageLocation) {
        return ObjectStorage.read(storageLocation, WorkOrder.class, storableInfo, getObjectMapper());
    }

    /**
     * Read a {@link WorkOrder} from json
     * @param content The {@link JsonContent} to read
     * @return The {@link WorkOrder} object constructed from the json
     */
    public static WorkOrder readFromJson(JsonContent content) {
        return ObjectStorage.read(content, WorkOrder.class, getObjectMapper());
    }


    /**
     * Delete a WorkOrder from the repo, using its member fields to find it.
     * @param user The user doing the delete
     * @param comment The comment associated with the delete
     * @return
     */
    public static Boolean deleteByFields(String workOrderURI, String user, String comment) {
        RaptureURI storageLocation 
          = new WorkOrderPathBuilder()
           .workOrderURI(workOrderURI)
                  .buildStorageLocation();
        return ObjectStorage.delete(user, storageLocation, storableInfo.getIndexInfo(), comment);
    }

    /**
     * Delete a WorkOrder from the repo.
     * @param storageLocation The storage location of the object in the repo
     * @param user The user doing the delete
     * @param comment The comment associated with the delete
     * @return
     */
    public static Boolean deleteByStorageLocation(RaptureURI storageLocation, String user, String comment) {
            return ObjectStorage.delete(user, storageLocation, storableInfo.getIndexInfo(), comment);
    }

    /**
     * Store a WorkOrder into the repo, and add a comment
     * 
     * @param doc
     *            The WorkOrder that will be stored
     * @param user
     *            The user doing the storing
     * @param comment
     */
    public static void add(WorkOrder storable, String user, String comment) {
        ObjectStorage.write(storable, user, storableInfo, comment, getObjectMapper());
    }

    /**
     * Run a query on the repo where the index of WorkOrder is stored
     * @param query
     * @return
     */
    public static TableQueryResult queryIndex(String query) {
        return ObjectStorage.queryIndex(storableInfo, WorkOrderPathBuilder.getRepoName(), query);
    }

    /**
     * Return a {@link WorkOrder} based on its address
     * 
     * @param addressURI The address for this WorkOrder
     * @return The {@link WorkOrder} object stored at this address
     */
    public static WorkOrder readByAddress(RaptureURI addressURI) {
        RaptureURI storageLocation = StorageLocationFactory.createStorageURI(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), addressURI);
        return ObjectStorage.read(storageLocation, WorkOrder.class, storableInfo, getObjectMapper());
    }
      

    /**
     * Delete a WorkOrder from the repo, based on the object's Address.
     * @param addressURI The public address URI of the object to be deleted
     * @param user The user doing the delete
     * @param comment The comment associated with the delete
     * @return
     */
    public static Boolean deleteByAddress(RaptureURI addressURI, String user, String comment) {
        RaptureURI storageLocation = StorageLocationFactory.createStorageURI(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), addressURI);
        return deleteByStorageLocation(storageLocation, user, comment);
    }

    /**
     * Return the storageLocation for this WorkOrder, converted from the address
     * @param addressURI The public address URI of the WorkOrder
     * @return
     */
    public static RaptureURI addressToStorageLocation(RaptureURI addressURI) {
        return StorageLocationFactory.createStorageURI(WorkOrderPathBuilder.getRepoName(), WorkOrderPathBuilder.getPrefix(), addressURI);
    }


    /**
     * Get the ObjectMapper for this object
     * 
     * @return The ObjectMapper
     */
    private static ObjectMapper getObjectMapper() {
        return StorableObjectMapper.getMapper();
    }

    static {
        StorableObjectMapper.addSerDes(WorkOrder.class, new WorkOrderSerializer(), new WorkOrderDeserializer());
    }

    private static class WorkOrderDeserializer extends JsonDeserializer {

        @Override
        public WorkOrder deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
            WorkOrder workOrder = JacksonUtil.DEFAULT_MAPPER.readValue(p, WorkOrder.class);

            workOrder.set_raptureVersion(ServerApiVersion.getApiVersion());
            return workOrder;
        }
    }

    private static class WorkOrderSerializer extends com.fasterxml.jackson.databind.JsonSerializer {
        @Override
        public void serialize(WorkOrder value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
            value.set_raptureVersion(ServerApiVersion.getApiVersion());
            gen.writeRaw(JacksonUtil.DEFAULT_MAPPER.writeValueAsString(value));
        }
    }
}	




© 2015 - 2025 Weber Informatics LLC | Privacy Policy