Fedora Commons Iformation - fedora-commons

I'm using fedora commons 3.7 and fedora-client 0.7 and I'm really newbie to fedora commons...so pardon me if I do very basic questions As far as I know, in order to use fedora repository I have to use the fedora web application and the best is to deploy with the embedded tomcat; am I right?
Moreover, I was able in uploading a file to the fedora repository; in order to do it I wrote this simple test case:
#Test
public void ingestFile()
{
try
{
File toUpload = new File("/home/angelo/Scrivania/test.odt");
FedoraCredentials fc = new FedoraCredentials("http://localhost:8080/fedora", "fedoraAdmin", "fedoraAdmin");
FedoraClient fcRepoClient = new FedoraClient(fc);
FedoraRequest.setDefaultClient(fcRepoClient);
Ingest in = new Ingest();
IngestResponse ir = in.execute();
AddDatastream ads = new AddDatastream(ir.getPid(), toUpload.getName());
//Mime type util
ContentInfoUtil cif = new ContentInfoUtil();
ContentInfo ci = cif.findMatch(toUpload);
if( ci != null && ci.getMimeType() != null && !ci.getMimeType().trim().equals("") )
{
ads.mimeType(ci.getMimeType());
}
ads.controlGroup("M");
ads.content(toUpload);
AddDatastreamResponse adsr = ads.execute();
logger.info(adsr.getDatastreamProfile().getPid());
} catch (Exception e)
{
logger.error(e.getMessage(), e);
}
}
All is pretty working Now...let's suppose I need to add some other properties to the file I want to upload (e.g. copyright stuffs, description, dates and so on....) and let's suppose I have to be able to do search on this properties... is it possible? If so...how can I do it? Should I create a new Datastream and make a relation between the one of my file and the new datastream? Shouls I create my own FOXML and provide it to the datastream? May anybody give me a tip regarding to this problem?
Any suggestion would be great
Thank you
Angelo

Related

How to use parquet files as a source for can in Apache Calcite?

I want to read from a parquet file as from a table using Apache Calcite. There are bunch of adapters listed in the docs, but no explicit one for parquet. From the other hand there is adapter for Spark, which can deal with Parquet perfectly. But for some reason I can't really find any example of how to use this spark adapter. Even reading it's code I can't say I understand how I need to define Spark's schemas. There is no factory for it... I've tried following code without really understanding how it should work and it obviously doesn't work:
Class.forName("org.apache.calcite.jdbc.Driver");
Properties info = new Properties();
info.setProperty("lex", "JAVA");
info.setProperty("spark", "true");
Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
SparkSession spark = SparkSession.builder()
.appName("test")
.master("local[1]")
.getOrCreate();
StopWatch w = StopWatch.createStarted();
Dataset<Row> ds = spark.read().parquet("/tmp/test.parquet");
ds.select("issue_desc", "valid_from_dttm").show(15);
ds.printSchema();
ds.createTempView("sparkTable");
System.out.println(w.getTime(TimeUnit.MILLISECONDS));
FrameworkConfig calciteConfig = Frameworks.newConfigBuilder()
.parserConfig(SqlParser.Config.DEFAULT)
.defaultSchema(rootSchema)
.programs()
.traitDefs(ConventionTraitDef.INSTANCE, RelDistributionTraitDef.INSTANCE)
.build();
RelBuilder builder = RelBuilder.create(calciteConfig);
RelRunner relRunner = calciteConnection.unwrap(RelRunner.class);
RelNode test1 = builder
.scan("sparkTable")
.build();
executeNode(relRunner, test1);
It simply fails with the exception:
Exception in thread "main" org.apache.calcite.runtime.CalciteException: Table 'sparkTable' not found
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:506)
at org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:600)
at org.apache.calcite.tools.RelBuilder.scan(RelBuilder.java:1238)
at org.apache.calcite.tools.RelBuilder.scan(RelBuilder.java:1265)
at ru.tinkoff.dwh.hercule.demo.SparkTest.main(SparkTest.java:64)
Could please somebody explain how to use it, or share an example, or explain why I can't use spark adapter like this?

Create company in unit test

I have a unit-test in which I need to create a company and create/write data in that companys context. However it seems the company gets created, but I can't change my context.
i use this method to create the company:
private void CreateCompany(str companyName, str companyDisplayName, str countryRegion)
{
var model = new OMNewLegalEntityViewModel();
model.parmCompany(companyName);
model.parmName(companyDisplayName);
model.parmCountryRegion(countryRegion);
model.createLegalEntity();
}
And i check if a company exists with this method:
public boolean CompanyExists(str company)
{
CompanyInfo companyInfo;
select firstonly * from companyInfo
where companyInfo.DataArea == company;
if(companyInfo)
{
return true;
}
//fallback
return false;
}
The following is a shortened version of what is happening in my test method:
if(!this.CompanyExists('XXX'))
{
this.CreateCompany('XXX','XXX','DEU');
boolean companyCreated = this.CompanyExists('XXX');
this.assertTrue(companyCreated);
}
changecompany('XXX')
{
//do something
}
The changecompany throws an error that the company does not exist.
Am I missing something crucial?
I was able to test your given code without problems using the newest update of Dynamics Operations installed. Maybe try updating your system if not already done and check if that helps.
Version in use:
Platform build: 7.0.5286.41360
Platform version: Update27
Product build: 10.0.107.20005
Product version: 10

Unit Testing ODataQueryOptions Gives MissingMethodException DependencyInjection

So here is my problem, I have an OData Web Api service that uses ODataQueryOptions to filter data from our sql server and I am trying to setup a .Net Framework Unit Test project to test the controllers with different query options. I have been searching for several days now and found many examples but most of them use an older version of OData. This example is the best one I have found so far, the only problem is that calling config.EnableDependencyInjection(); gives me the following exception:
Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
Here is an example of my code:
using System.Collections.Generic;
using System.Web.Http.Results;
using System.Web.OData;
using System.Web.OData.Query;
using System.Net.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using University.API.OData.Controllers;
using University.API.OData.Models;
using System.Web.OData.Routing;
using System.Web.Http;
using System.Web.OData.Extensions;
[TestClass]
public class SalesforceUnitTest
{
private HttpRequestMessage request;
private ODataQueryOptions<Product> _options;
[TestInitialize]
public void TestInitialize()
{
request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/odata/product?$top=5");
var model = WebApiConfig.GetModel();
HttpConfiguration config = new HttpConfiguration();
config.EnableDependencyInjection(); //Throws Missing Method Exception
WebApiConfig.Register(config);
config.EnsureInitialized();
request.SetConfiguration(config);
ODataQueryContext context = new ODataQueryContext(
model,
typeof(Product),
new ODataPath(
new Microsoft.OData.UriParser.EntitySetSegment(
model.EntityContainer.FindEntitySet("product"))
)
);
_options = new ODataQueryOptions<Product>(context, request);
}
[TestMethod]
public void ProductTest()
{
var controller = new ProductController();
controller.Request = request;
var response = controller.Get(_options);
var contentResult = response as OkNegotiatedContentResult<List<Product>>;
Assert.IsNotNull(contentResult);
Assert.IsNotNull(contentResult.Content);
}
}
Let me know if there is any other information you may need.
Thank you for any help you can provide.
EDIT:
Here what is referenced in the unit test project:
EntityFramework
EntityFramework.SqlServer
Microsoft.Data.Edm
Microsoft.Data.OData
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.DependencyInjection.Abstractions
Microsoft.OData.Core
Microsoft.Odata.Edb
Microsoft.Spatial
Microsoft.Threading.Tasks
Microsoft.Threading.Tasks.Extensions
Microsoft.Threading.Tasks.Extensions.Desktop
Microsoft.VisualStudio.TestPlatform.TestFramework
Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions
System
System.ComponentModel.DataAnnotations
System.Net
System.Net.Http
System.Net.Http.Extensions
System.Net.Http.Primitives
System.Net.Http.WebRequest.
System.Spatial
System.Web
System.Web.Http
System.Web.OData
ODataAPI
I figured it out after some more digging. It seems that my Unit Test project was using a different version than my ODataApi project. This for some weird reason was causing the MissingMethodException instead of a VersionMismatchException. Hopefully this helps someone else who is looking into why Dependency Injection isnt working for your Unit Test project.

Google OCR language hints

It says on the documentation page here: https://cloud.google.com/vision/docs/ocr that you can specify language hints to help OCR more accurately detect text in the image. Does anyone know where I would specify a language hint in my code? I am programming it using a .net console application.
using Google.Cloud.Vision.V1;
using System;
namespace GoogleCloudSamples
{
public class QuickStart
{
public static void Main(string[] args)
{
// Instantiates a client
var client = ImageAnnotatorClient.Create();
// Load the image file into memory
var image = Image.FromFile("wakeupcat.jpg");
// Performs label detection on the image file
var response = client.DetectLabels(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
Console.WriteLine(annotation.Description);
}
}
}
}
I can't seem to access the language hints property of the ImageContext class because it is read only. Is there a way to create an ImageContext where I can specify the language hints?
You can create ImageContext object & set it in your AnnotateImageRequest using:
// Build ImageContext object
ImageContext imageContext = ImageContext.newBuilder().addLanguageHints("en").build();
// Set it to AnnotateImageRequest
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).setImageContext(imageContext).build();
I had same problem and solved it. LanguageHints is List. You can add language. Of course you can add multiple languages also.
ImageContext imageContext = new ImageContext();
imageContext.LanguageHints.Add("en");
imageContext.LanguageHints.Add("ko");

Using NAudio/Nlayer to mix two mp3 files

In reference to this question: NoDriver calling acmFormatSuggest on Azure
My hosting server does not allow me to install anything or register dlls. I am using Naudio to mix to mp3 files and it gave me the error NoDriver calling acmFormatSuggest.
I downloaded and installed Nlayer in my application and modified the code to look like this:
var builderBackground = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
var builderMessage = new Mp3FileReader.FrameDecompressorBuilder(wf => new Mp3FrameDecompressor(wf));
Mp3FileReader mpbacground = new Mp3FileReader(ThumbAudioMP3, builderBackground); Mp3FileReader mpMessage = new Mp3FileReader(stream, builderMessage);
background = WaveFormatConversionStream.CreatePcmStream(mpbacground);
message = WaveFormatConversionStream.CreatePcmStream(mpMessage);
var mixer = new WaveMixerStream32(); var messageOffsetted = new WaveOffsetStream(message, TimeSpan.FromSeconds(0), TimeSpan.Zero, TimeSpan.FromSeconds(seconds));
I get the same NoDriver calling acmFormatSuggest error in the line WaveFormatConversionStream.CreatePcmStream(...
Can someone tell me how I should be doing this? Any documentation on Nlayer?
You don't need the WaveFormatConversionStream.CreatePcmStream lines. The Mp3FileReader classes will already emit PCM.