예제 #1
0
        private void CommitIconToWS()
        {
            try
            {
                logger.Info("post icon");
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ImageIO.write(GetIcon(), "png", baos);
                baos.flush();
                byte[] imageInByte = baos.toByteArray();
                baos.close();

                String resource = REQUEST.API_PATH_V1
                        + REQUEST.CLASSES.PATH
                        + GetName() + "/"
                        + REQUEST.CLASSES.ICON.PATH;

                HttpURLConnection connection = ds.getHTTPConnection().getPostIconConnection(resource);


                OutputStream os = connection.getOutputStream();

                os.write(imageInByte);
                os.flush();
                os.close();

                //
                int responseCode = connection.getResponseCode();
                logger.Error("commit icon: {}", responseCode);



                catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
예제 #2
0
        public int addSamples(List <JEVisSample> samples)
        {
            List <JsonSample> jsonSamples = new ArrayList <>();
            int imported = 0;

            int primType = getPrimitiveType();

            if (primType != JEVisConstants.PrimitiveType.FILE)
            {
                try {
                    for (JEVisSample s : samples)
                    {
                        JsonSample jsonSample = JsonFactory.buildSample(s, primType);
                        jsonSamples.add(jsonSample);
                    }


//JEWebService/v1/files/8598/attributes/File/samples/files/20180604T141441?filename=nb-configuration.xml
//JEWebService/v1/objects/{id}/attributes/{attribute}/samples
                    String resource = REQUEST.API_PATH_V1
                                      + REQUEST.OBJECTS.PATH
                                      + getObjectID() + "/"
                                      + REQUEST.OBJECTS.ATTRIBUTES.PATH
                                      + getName() + "/"
                                      + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.PATH;

//                String requestjson = new Gson().toJson(jsonSamples, new TypeToken<List<JsonSample>>() {
//                }.getType());
                    String json = this.ds.getObjectMapper().writeValueAsString(jsonSamples);

//                logger.debug("Payload. {}", requestjson);
/** TODO: implement this function into ws **/
                    StringBuffer response = ds.getHTTPConnection().postRequest(resource, json);

                    logger.debug("Response.payload: {}", response);
                } catch (Exception ex)
                {
                    logger.catching(ex);
                }
            }
            else
            {
                //Also upload die byte file, filename is in json
                for (JEVisSample s : samples)
                {
                    try
                    {
                        String resource = REQUEST.API_PATH_V1
                                          + REQUEST.OBJECTS.PATH
                                          + getObjectID() + "/"
                                          + REQUEST.OBJECTS.ATTRIBUTES.PATH
                                          + getName() + "/"
                                          + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.PATH
                                          + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.FILES.PATH
                                          + HTTPConnection.FMT.print(s.getTimestamp())
                                          + "?" + REQUEST.OBJECTS.ATTRIBUTES.SAMPLES.FILES.OPTIONS.FILENAME + s.getValueAsFile().getFilename();

                        HttpURLConnection connection = ds.getHTTPConnection().getPostFileConnection(resource);
                        //                    logger.trace("Upload file-------------: {}", s.getValueAsFile().getBytes().length);
                        try (OutputStream os = connection.getOutputStream()) {
                                os.write(s.getValueAsFile().getBytes());
                                os.flush();
                                os.close();
                            }
                        int responseCode = connection.getResponseCode();
                        imported = 1;/** TODO: fix server side, missing response **/
                    } catch (Exception ex)
                    {
                        logger.catching(ex);
                    }
                }

//
            }
            ds.reloadAttribute(this);

/**
 * cast needs to be removed
 */
            JEVisObjectWS obj = (JEVisObjectWS)getObject();

            obj.notifyListeners(new JEVisEvent(this, JEVisEvent.TYPE.ATTRIBUTE_UPDATE, this));


            return(imported);
        }