Search in sources :

Example 1 with SServiceDescriptor

use of org.bimserver.interfaces.objects.SServiceDescriptor in project BIMserver by opensourceBIM.

the class ServiceImpl method sort.

@SuppressWarnings("unchecked")
private List<SServiceDescriptor> sort(List<SServiceDescriptor> sServiceDescriptors) {
    ComparatorChain comparatorChain = new ComparatorChain();
    comparatorChain.addComparator(new Comparator<SServiceDescriptor>() {

        @Override
        public int compare(SServiceDescriptor o1, SServiceDescriptor o2) {
            return o1.getProviderName().compareTo(o2.getProviderName());
        }
    });
    comparatorChain.addComparator(new Comparator<SServiceDescriptor>() {

        @Override
        public int compare(SServiceDescriptor o1, SServiceDescriptor o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    Collections.sort(sServiceDescriptors, comparatorChain);
    return sServiceDescriptors;
}
Also used : ComparatorChain(org.apache.commons.collections.comparators.ComparatorChain) SServiceDescriptor(org.bimserver.interfaces.objects.SServiceDescriptor)

Example 2 with SServiceDescriptor

use of org.bimserver.interfaces.objects.SServiceDescriptor in project BIMserver by opensourceBIM.

the class ServiceImpl method getAllServiceDescriptors.

@Override
public List<SServiceDescriptor> getAllServiceDescriptors() throws ServerException, UserException {
    requireRealUserAuthentication();
    try {
        List<SServiceDescriptor> sServiceDescriptors = new ArrayList<SServiceDescriptor>();
        URL url = new URL(getServiceMap().get(SettingsInterface.class).getServiceRepositoryUrl() + "/services.json");
        String content = NetUtils.getContent(url, 5000);
        JSONObject root = new JSONObject(new JSONTokener(content));
        JSONArray services = root.getJSONArray("services");
        for (int i = 0; i < services.length(); i++) {
            JSONObject service = services.getJSONObject(i);
            SServiceDescriptor sServiceDescriptor = new SServiceDescriptor();
            sServiceDescriptor.setName(service.getString("name"));
            sServiceDescriptor.setIdentifier(service.getString("identifier"));
            sServiceDescriptor.setDescription(service.getString("description"));
            sServiceDescriptor.setNotificationProtocol(SAccessMethod.valueOf(service.getString("notificationProtocol")));
            sServiceDescriptor.setTrigger(STrigger.valueOf(service.getString("trigger")));
            sServiceDescriptor.setUrl(service.getString("url"));
            sServiceDescriptor.setCompanyUrl(service.getString("companyUrl"));
            sServiceDescriptor.setTokenUrl(service.getString("tokenUrl"));
            sServiceDescriptor.setNewProfileUrl(service.getString("newProfileUrl"));
            sServiceDescriptor.setProviderName(service.getString("providerName"));
            sServiceDescriptor.setRegisterUrl(service.getString("registerUrl"));
            sServiceDescriptor.setAuthorizeUrl(service.getString("authorizeUrl"));
            JSONObject rights = service.getJSONObject("rights");
            sServiceDescriptor.setReadRevision(rights.has("readRevision") && rights.getBoolean("readRevision"));
            sServiceDescriptor.setReadExtendedData(rights.has("readExtendedData") ? rights.getString("readExtendedData") : null);
            sServiceDescriptor.setWriteRevision(rights.has("writeRevision") && rights.getBoolean("writeRevision"));
            sServiceDescriptor.setWriteExtendedData(rights.has("writeExtendedData") ? rights.getString("writeExtendedData") : null);
            sServiceDescriptors.add(sServiceDescriptor);
        }
        sort(sServiceDescriptors);
        return sServiceDescriptors;
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : JSONTokener(org.codehaus.jettison.json.JSONTokener) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) SServiceDescriptor(org.bimserver.interfaces.objects.SServiceDescriptor) URL(java.net.URL) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Example 3 with SServiceDescriptor

use of org.bimserver.interfaces.objects.SServiceDescriptor in project BIMserver by opensourceBIM.

the class ServiceImpl method getServiceDescriptor.

@Override
public SServiceDescriptor getServiceDescriptor(String baseUrl, String serviceIdentifier) throws ServerException, UserException {
    requireRealUserAuthentication();
    try {
        try (BimServerClientFactory factory = new JsonBimServerClientFactory(baseUrl, getBimServer().getServicesMap(), getBimServer().getJsonSocketReflectorFactory(), getBimServer().getReflectorFactory(), getBimServer().getMetaDataManager())) {
            BimServerClientInterface client = factory.create();
            SServiceDescriptor service = client.getRemoteServiceInterface().getService(serviceIdentifier);
            if (service == null) {
                throw new UserException("No service found with identifier " + serviceIdentifier);
            }
            service.setUrl(baseUrl);
            return service;
        }
    } catch (Exception e) {
        return handleException(e);
    }
}
Also used : JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) UserException(org.bimserver.shared.exceptions.UserException) SServiceDescriptor(org.bimserver.interfaces.objects.SServiceDescriptor) JsonBimServerClientFactory(org.bimserver.client.json.JsonBimServerClientFactory) BimServerClientFactory(org.bimserver.shared.BimServerClientFactory) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) SerializerException(org.bimserver.plugins.serializers.SerializerException) BcfException(org.opensourcebim.bcf.BcfException) UserException(org.bimserver.shared.exceptions.UserException) CannotBeScheduledException(org.bimserver.longaction.CannotBeScheduledException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException)

Aggregations

SServiceDescriptor (org.bimserver.interfaces.objects.SServiceDescriptor)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 MessagingException (javax.mail.MessagingException)2 AddressException (javax.mail.internet.AddressException)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)2 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)2 SerializerException (org.bimserver.plugins.serializers.SerializerException)2 ServerException (org.bimserver.shared.exceptions.ServerException)2 UserException (org.bimserver.shared.exceptions.UserException)2 BcfException (org.opensourcebim.bcf.BcfException)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ComparatorChain (org.apache.commons.collections.comparators.ComparatorChain)1 JsonBimServerClientFactory (org.bimserver.client.json.JsonBimServerClientFactory)1 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)1 BimServerClientFactory (org.bimserver.shared.BimServerClientFactory)1 SettingsInterface (org.bimserver.shared.interfaces.SettingsInterface)1