<commit_before>/*
 * $Id$
 * $Revision$
 * $Date$
 * $Author$
 *
 * The DOMS project.
 * Copyright (C) 2007-2010  The State and University Library
 *
 * 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 dk.statsbiblioteket.doms.client;


import dk.statsbiblioteket.doms.central.*;
import dk.statsbiblioteket.doms.client.exceptions.NoObjectFound;
import dk.statsbiblioteket.doms.client.exceptions.ServerOperationFailed;
import dk.statsbiblioteket.doms.client.exceptions.XMLParseException;
import dk.statsbiblioteket.doms.client.impl.objects.DigitalObjectFactoryImpl;
import dk.statsbiblioteket.doms.client.objects.DigitalObject;
import dk.statsbiblioteket.doms.client.relations.*;
import dk.statsbiblioteket.doms.client.objects.DigitalObjectFactory;
import dk.statsbiblioteket.doms.client.relations.Relation;
import dk.statsbiblioteket.doms.client.utils.Constants;
import dk.statsbiblioteket.doms.client.utils.FileInfo;
import dk.statsbiblioteket.util.xml.DOM;
import org.w3c.dom.Document;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.BindingProvider;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.String;
import java.net.URL;
import java.util.*;

/**
 * Utility class for making it simple and easy to access the DOMS server main
 * web service.
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 * @author <NAME> &lt;<EMAIL>&gt;
 * @deprecated A new implementation should be made around the domsClient - common
 */
public class DomsWSClientImpl implements DomsWSClient {

    private static final QName CENTRAL_WEBSERVICE_SERVICE = new QName(
            "http://central.doms.statsbiblioteket.dk/",
            "CentralWebserviceService");
    /**
     * Reference to the active DOMS webservice client instance.
     */
    private CentralWebservice domsAPI;

    private DigitalObjectFactory dof = new DigitalObjectFactoryImpl(domsAPI);

    @Deprecated
    public void login(URL domsWSAPIEndpoint, String userName, String password) {
        setCredentials(domsWSAPIEndpoint, userName, password);
    }

    @Override
    public DigitalObjectFactory getDigitalObjectFactory(){
        return dof;
    }

    @Override
    public List<String> getLabel(List<String> uuids) {
        // domsAPI.getLabels(uuids);
        // TODO Implement the get label method on the server side.
        return uuids;
    }

    @Override
    public String getLabel(String uuid) {
        ArrayList lst = new ArrayList();
        lst.add(uuid);
        return getLabel(lst).get(0);
    }

    @Override
    public List<SearchResult> search(String query, int offset, int pageLength) throws ServerOperationFailed {
        List<dk.statsbiblioteket.doms.central.SearchResult> wresults;
        try {
            wresults = domsAPI.findObjects(query, offset, pageLength);
            /*List<SearchResult> cresults = new ArrayList<SearchResult>();
            for (dk.statsbiblioteket.doms.central.SearchResult wresult : wresults) {
                SearchResult cresult = new SearchResult(wresult.getPid(),
                                                        wresult.getType(),
                                                        wresult.getTitle(),
                                                        FedoraState.fromString(wresult.getState()),
                                                        new Date(wresult.getModifiedDate()),
                                                        new Date(wresult.getCreatedDate()));
                cresults.add(cresult);
        } */
            return wresults;
        } catch (Exception exception) {
            throw new ServerOperationFailed(
                    "Failed searching", exception);
        }
    }

    public void setCredentials(URL domsWSAPIEndpoint, String userName,
                               String password) {
        domsAPI = new CentralWebserviceService(domsWSAPIEndpoint,
                CENTRAL_WEBSERVICE_SERVICE).getCentralWebservicePort();

        Map<String, Object> domsAPILogin = ((BindingProvider) domsAPI)
                .getRequestContext();
        domsAPILogin.put(BindingProvider.USERNAME_PROPERTY, userName);
        domsAPILogin.put(BindingProvider.PASSWORD_PROPERTY, password);
    }

    public String createObjectFromTemplate(String templatePID, String comment)
            throws ServerOperationFailed {
        try {
            return domsAPI.newObject(templatePID, new ArrayList<String>(), comment);
        } catch (Exception exception) {
            throw new ServerOperationFailed(
                    "Failed creating a new object from template: "
                            + templatePID, exception);<commit_msg>Don't initialise dof with null API<commit_after>/*
 * $Id$
 * $Revision$
 * $Date$
 * $Author$
 *
 * The DOMS project.
 * Copyright (C) 2007-2010  The State and University Library
 *
 * 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 dk.statsbiblioteket.doms.client;


import dk.statsbiblioteket.doms.central.*;
import dk.statsbiblioteket.doms.client.exceptions.NoObjectFound;
import dk.statsbiblioteket.doms.client.exceptions.ServerOperationFailed;
import dk.statsbiblioteket.doms.client.exceptions.XMLParseException;
import dk.statsbiblioteket.doms.client.impl.objects.DigitalObjectFactoryImpl;
import dk.statsbiblioteket.doms.client.objects.DigitalObject;
import dk.statsbiblioteket.doms.client.relations.*;
import dk.statsbiblioteket.doms.client.objects.DigitalObjectFactory;
import dk.statsbiblioteket.doms.client.relations.Relation;
import dk.statsbiblioteket.doms.client.utils.Constants;
import dk.statsbiblioteket.doms.client.utils.FileInfo;
import dk.statsbiblioteket.util.xml.DOM;
import org.w3c.dom.Document;

import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.ws.BindingProvider;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.String;
import java.net.URL;
import java.util.*;

/**
 * Utility class for making it simple and easy to access the DOMS server main
 * web service.
 *
 * @author <NAME> &lt;<EMAIL>&gt;
 * @author <NAME> &lt;<EMAIL>&gt;
 * @deprecated A new implementation should be made around the domsClient - common
 */
public class DomsWSClientImpl implements DomsWSClient {

    private static final QName CENTRAL_WEBSERVICE_SERVICE = new QName(
            "http://central.doms.statsbiblioteket.dk/",
            "CentralWebserviceService");
    /**
     * Reference to the active DOMS webservice client instance.
     */
    private CentralWebservice domsAPI;

    private DigitalObjectFactory dof;

    @Deprecated
    public void login(URL domsWSAPIEndpoint, String userName, String password) {
        setCredentials(domsWSAPIEndpoint, userName, password);
    }

    @Override
    public DigitalObjectFactory getDigitalObjectFactory(){
        return dof;
    }

    @Override
    public List<String> getLabel(List<String> uuids) {
        // domsAPI.getLabels(uuids);
        // TODO Implement the get label method on the server side.
        return uuids;
    }

    @Override
    public String getLabel(String uuid) {
        ArrayList lst = new ArrayList();
        lst.add(uuid);
        return getLabel(lst).get(0);
    }

    @Override
    public List<SearchResult> search(String query, int offset, int pageLength) throws ServerOperationFailed {
        List<dk.statsbiblioteket.doms.central.SearchResult> wresults;
        try {
            wresults = domsAPI.findObjects(query, offset, pageLength);
            /*List<SearchResult> cresults = new ArrayList<SearchResult>();
            for (dk.statsbiblioteket.doms.central.SearchResult wresult : wresults) {
                SearchResult cresult = new SearchResult(wresult.getPid(),
                                                        wresult.getType(),
                                                        wresult.getTitle(),
                                                        FedoraState.fromString(wresult.getState()),
                                                        new Date(wresult.getModifiedDate()),
                                                        new Date(wresult.getCreatedDate()));
                cresults.add(cresult);
        } */
            return wresults;
        } catch (Exception exception) {
            throw new ServerOperationFailed(
                    "Failed searching", exception);
        }
    }

    public void setCredentials(URL domsWSAPIEndpoint, String userName,
                               String password) {
        domsAPI = new CentralWebserviceService(domsWSAPIEndpoint,
                CENTRAL_WEBSERVICE_SERVICE).getCentralWebservicePort();

        Map<String, Object> domsAPILogin = ((BindingProvider) domsAPI)
                .getRequestContext();
        domsAPILogin.put(BindingProvider.USERNAME_PROPERTY, userName);
        domsAPILogin.put(BindingProvider.PASSWORD_PROPERTY, password);
        dof = new DigitalObjectFactoryImpl(domsAPI);
    }

    public String createObjectFromTemplate(String templatePID, String comment)
            throws ServerOperationFailed {
        try {
            return domsAPI.newObject(templatePID, new ArrayList<String>(), comment);
        } catch (Exception exception) {
            throw new ServerOperationFailed(
                    "Failed creating a new object from template: "
                            + templatePID, exception);
{'fraction_non_alphanumeric': 0.08380192272809722, 'fraction_numerical': 0.002539452203881734, 'mean_word_length': 2.724079702803107, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7153538', 'n_tokens_mistral': 3001, 'n_tokens_neox': 2885, 'n_words': 775}