Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2021 Cognite AS
*
* Licensed 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 com.cognite.client;
import com.cognite.client.dto.ConvertResponse;
import com.cognite.client.dto.DiagramResponse;
import com.cognite.client.dto.FileBinary;
import com.cognite.client.dto.Item;
import com.cognite.client.servicesV1.ConnectorServiceV1;
import com.cognite.client.servicesV1.ItemReader;
import com.cognite.client.servicesV1.ResponseItems;
import com.cognite.client.servicesV1.parser.DiagramResponseParser;
import com.cognite.client.util.Partition;
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import com.google.protobuf.Struct;
import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Duration;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.stream.Collectors;
/**
* This class represents the Cognite engineering api endpoint
*
* It provides methods for detecting entities, annotating and creating interactive diagrams.
*/
@AutoValue
public abstract class EngineeringDiagrams extends ApiBase {
private static Builder builder() {
return new AutoValue_EngineeringDiagrams.Builder();
}
protected static final Logger LOG = LoggerFactory.getLogger(EngineeringDiagrams.class);
/**
* Construct a new {@link EngineeringDiagrams} object using the provided configuration.
*
* This method is intended for internal use--SDK clients should always use {@link CogniteClient}
* as the entry point to this class.
*
* @param client The {@link CogniteClient} to use for configuration settings.
* @return The datasets api object.
*/
public static EngineeringDiagrams of(CogniteClient client) {
return EngineeringDiagrams.builder()
.setClient(client)
.build();
}
/**
* Detect references to assets and files, etc. from a P&ID and annotate them with bounding boxes.
* The P&ID must be a single-page PDF file or an image with JPEG, PNG or TIFF format.
*
* The detection will perform complete matches (i.e. partial matches are not accepted).
*
* @param files The engineering diagram files to process.
* @param entities The entities to use for matching.
* @param searchField The entity attribute to use for string matching.
* @param convertToInteractive If set to {@code true} then an interactive diagram (SVG) will be included in the results.
* @return The results from the detect annotations job(s).
* @throws Exception
*/
public List detectAnnotations(Collection files,
Collection entities,
String searchField,
boolean convertToInteractive) throws Exception {
return detectAnnotations(files, entities, searchField, false, 2, convertToInteractive);
}
/**
* Detect references to assets and files, etc. from an engineering diagram and annotate them with bounding boxes.
* The engineering diagram must be a PDF file or an image with JPEG, PNG or TIFF format.
*
* @param files The engineering diagram files to process.
* @param entities The entities to use for matching.
* @param searchField The entity attribute to use for string matching.
* @param partialMatch If set to {@code true}, use partial matching
* @param minTokens The minimum number of tokens (consecutive letters/numbers) required for a match.
* @param convertToInteractive If set to {@code true} then an interactive P&ID (SVG) will be included in the results.
* @return The results from the detect annotations job(s).
* @throws Exception
*/
public List detectAnnotations(Collection files,
Collection entities,
String searchField,
boolean partialMatch,
int minTokens,
boolean convertToInteractive) throws Exception {
final String loggingPrefix = "detectAnnotationsDiagrams() - batch: " + RandomStringUtils.randomAlphanumeric(4) + " - ";
Preconditions.checkNotNull(files, loggingPrefix + "Files cannot be null.");
Preconditions.checkNotNull(entities, loggingPrefix + "Entities cannot be null.");
Preconditions.checkNotNull(searchField, loggingPrefix + "Search field cannot be null.");
LOG.debug(loggingPrefix + "Received {} files to process for {} entities. Search field: {}, partial match: {}, "
+ "min tokens: {}, convert to SVG: {}",
files.size(),
entities.size(),
searchField,
partialMatch,
minTokens,
convertToInteractive);
if (files.isEmpty() || entities.isEmpty()) {
LOG.info(loggingPrefix + "Files list or entities list is empty. Will ignore the request and return an empty response.");
return Collections.emptyList();
}
// Build the baseline request.
Request detectAnnotations = Request.create()
.withRootParameter("entities", entities)
.withRootParameter("searchField", searchField)
.withRootParameter("partialMatch", partialMatch)
.withRootParameter("minTokens", minTokens);
// Build the item batches
List> itemBatchesList = Partition.ofSize(new ArrayList<>(files), 2);
List requestBatches = new ArrayList<>();
for (List fileBatch : itemBatchesList) {
List