[Scada-LTS] The possibility to add image sets without requiring a reboot

start.png

[Scada-LTS] The possibility to add image sets without a restart

  • The Function for the system administrator.

Before the changes, the ScadaLTS program loaded images information once at startup and it was stored in memory for the entire duration of the program.

At the moment the administrator can add a picture to the resources by copying it to the appropriate directory and refresh cache images.



▶️ DTube
▶️ IPFS

How was it implemented?

I added: REST API - GET "/api/resources/imagesRefresh"

@Controller
public class ResourcesAPI {

    private static final Log LOG = LogFactory.getLog(ResourcesAPI.class);

    @Resource
    private ResourcesService resourcesService;

    @RequestMapping(value = "/api/resources/imagesRefresh", method = RequestMethod.GET)
    public ResponseEntity<String> imagesRefresh(HttpServletRequest request) {

        LOG.info("/api/resources/imagesRefresh");
        try {
            User user = Common.getUser(request);
            if (user != null && user.isAdmin()) {
                resourcesService.refreshImages();
                return new ResponseEntity<String>(HttpStatus.OK);
            } else {
                return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);
            }
        } catch (Exception e) {
             return new ResponseEntity<String>(e.toString(), HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}

I added the service:

@Service
public class ResourcesService {

    public void refreshImages() {
        ViewGraphicLoader loader = new ViewGraphicLoader();
        List<ImageSet> imageSets = new ArrayList<ImageSet>();
        List<DynamicImage> dynamicImages = new ArrayList<DynamicImage>();

        ServletContext ctx = Common.ctx.getCtx();

        for (ViewGraphic g : loader.loadViewGraphics(ctx.getRealPath(""))) {
            if (g.isImageSet())
                imageSets.add((ImageSet) g);
            else if (g.isDynamicImage())
                dynamicImages.add((DynamicImage) g);
            else
                throw new ShouldNeverHappenException(
                        "Unknown view graphic type");
        }

        ctx.setAttribute(Common.ContextKeys.IMAGE_SETS, imageSets);
        ctx.setAttribute(Common.ContextKeys.DYNAMIC_IMAGES, dynamicImages);

        Common.ctx = new ContextWrapper(ctx);

    }

}

I added a button in the System Settings tab.

<div class="borderDiv marB marR" style="float:left">
       <table width="100%">
          <tr>
             <td>
               <span class="smallTitle">Cache images</span>
             </td>
          </tr>
          <tr>
             <td>
               <button onClick="refreshImages()">Refresh</button>
             </td>
          </tr>
       </table>
  </div>

I added function refreshImages on a button click

 function refreshImages() {

        var pathArray = location.href.split( '/' );
        var protocol = pathArray[0];
        var host = pathArray[2];
        var appScada = pathArray[3];
        var myLocation;
        if (!myLocation) {
           myLocation = protocol + "//" + host + "/" + appScada + "/";
        }

        jQuery.ajax({
            type: 'GET',
            dataType: 'text',
            url:myLocation+"/api/resources/imagesRefresh",
            success: function(msg){
                alert("Success: the resource images has been refreshed");
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert("Problem when refreshing assets:"+errorThrown.message);
            }
        });

    }

The changes will be made in the release v0.0.9.4, which is planned the next week.

Pull request: 516

Issues: 509 485

Thank you.



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now