Example #1
0
 public void model_admin() {
   if (ajf != null) {
     ajf.dispose();
   }
   if (jf != null) {
     jf.dispose();
   }
   ajf = new AdminRunningFrame(this);
   ajf.startPage();
   if (DBfile.exists()) {
     try {
       cust = returnSavedData("p2.dat");
       if (cust.isEmpty()) {
         ajf.errorMessage("There are no customers in this database.");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
   if (logFile.exists()) {
     try {
       adminLogs = returnLog("p2.log");
       if (adminLogs.isEmpty()) {
         ajf.errorMessage("No entries have been found!");
       }
     } catch (ClassNotFoundException | IOException e) {
       e.printStackTrace();
     }
   }
 }
Example #2
0
  /**
   * Checks if the score is high enough to get to the high scores list, adds the name and score and
   * organizes the list. If HighScores.dat is not found, the method generates a blank one.
   *
   * @param name The nickname of the person getting to the list.
   * @param score The score gained.
   */
  public static void addHighScore(String name, int score) {

    // If we don't yet have a high scores table, we create a blank (and let the user know about it)
    if (!new File("HighScores.dat").exists()) {
      // This object matrix actually stores the information of the high scores list
      Object[][] highScores = new Object[10][3];
      // We fill the high scores list with blank entries:  #.    " "    0
      for (int i = 0; i < highScores.length; i++) {
        highScores[i][0] = (i + 1) + ".";
        highScores[i][1] = " ";
        highScores[i][2] = 0;
      }
      // This actually writes and makes the high scores file
      try {
        ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("HighScores.dat"));
        o.writeObject(highScores);
        o.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    // We read the file to check if we have a new high score, and then rewrite the highscore
    // This is done even if we didn't previously have a high scores list
    try {
      ObjectInputStream o = new ObjectInputStream(new FileInputStream("HighScores.dat"));
      // The object matrix does the same as the previous one.
      // Here we just take what we read from the HighScores.dat to the Object[][] HighScores.
      Object[][] highScores = (Object[][]) o.readObject();
      // Then we start searching for an entry for which the score is smaller than the achieved score
      for (int i = 0; i < highScores.length; i++) {
        if ((Integer) highScores[i][2] < score) {
          // Once found we start to move entries, which are below the score we had, downwards.
          // I.e. 10. becomes whatever 9. was. 9. becomes what 8. was etc...
          for (int j = 9; j > i; j--) {
            highScores[j][0] = (j + 1) + ".";
            highScores[j][1] = highScores[j - 1][1];
            highScores[j][2] = highScores[j - 1][2];
          }
          // Then we write the score and the name we just got to the correct place
          highScores[i][0] = (i + 1) + ".";
          highScores[i][1] = name;
          highScores[i][2] = score;
          // And break the loop.
          /*Maybe this could be avoided somehow? I haven't been able to come up with an easy way yet.*/
          break;
        }
      }
      try {
        // And finally we overwrite the HighScores.dat with our highScores object matrix
        ObjectOutputStream n = new ObjectOutputStream(new FileOutputStream("HighScores.dat"));
        n.writeObject(highScores);
        n.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } catch (ClassNotFoundException | IOException e) {
      e.printStackTrace();
    }
  }
Example #3
0
  /**
   * Creates a new configuration method
   *
   * @param backMenu Menu instance used to control its music
   */
  public Config(Menu backMenu) {

    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      try (ObjectInputStream entradaObjs =
          new ObjectInputStream(new FileInputStream("Saves" + File.separator + "config.dat"))) {
        configSave = (float[]) entradaObjs.readObject();
      }
    } catch (ClassNotFoundException
        | IOException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
      System.out.println(e.getMessage());
    }

    this.setSize(800, 300);
    this.add(fondo = new Fondo("fondoConfig.png"));
    this.setUndecorated(true);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images" + File.separator + "logo.png"));
    this.backMenu = backMenu;

    icon = new ImageIcon("Images/brick.png");

    fondo.setLayout(new BorderLayout());

    returns = CustomButton.createButton("Go Back", this.getGraphicsConfiguration(), 18);
    returns.addActionListener(this);

    musicSlider = new JSlider(JSlider.HORIZONTAL, -30, 0, (int) configSave[0]);
    musicSlider.setOpaque(false);
    musicSlider.setMajorTickSpacing(10);
    musicSlider.setMinorTickSpacing(2);
    musicSlider.setPaintTicks(true);

    volumeSlider = new JSlider(JSlider.HORIZONTAL, -30, 0, (int) configSave[1]);
    volumeSlider.setOpaque(false);
    volumeSlider.setMajorTickSpacing(10);
    volumeSlider.setMinorTickSpacing(2);
    volumeSlider.setPaintTicks(true);

    fondo.add(returns, BorderLayout.SOUTH);
    fondo.add(musicSlider, BorderLayout.NORTH);
    fondo.add(volumeSlider, BorderLayout.CENTER);

    try {
      this.getContentPane()
          .setCursor(
              Toolkit.getDefaultToolkit()
                  .createCustomCursor(
                      CompatibleImage.toCompatibleImage(
                          ImageIO.read(new File("Images" + File.separator + "cursor.png"))),
                      new Point(0, 0),
                      "cursor"));
    } catch (IOException ex) {
      Logger.getLogger(Menu.class.getName()).log(Level.SEVERE, null, ex);
    }

    this.setVisible(true);
  }
Example #4
0
  /**
   * Adds Attachemnts based on formData to task.
   *
   * @param oFormData FormData from task where we search file fields.
   * @param oTask where we add Attachments.
   */
  public void addAttachmentsToTask(FormData oFormData, DelegateTask oTask) {
    DelegateExecution oExecution = oTask.getExecution();

    LOG.info("SCAN:file");
    List<String> asFieldID = getListFieldCastomTypeFile(oFormData);
    LOG.info("[addAttachmentsToTask]");
    LOG.info("(asFieldID={})", asFieldID.toString());
    List<String> asFieldValue = getVariableValues(oExecution, asFieldID);
    LOG.info("(asFieldValue={})", asFieldValue.toString());
    List<String> asFieldName = getListCastomFieldName(oFormData);
    LOG.info("(asFieldName={})", asFieldName.toString());
    if (!asFieldValue.isEmpty()) {
      int n = 0;
      for (String sKeyRedis : asFieldValue) {
        LOG.info("(sKeyRedis={})", sKeyRedis);
        if (sKeyRedis != null
            && !sKeyRedis.isEmpty()
            && !"".equals(sKeyRedis.trim())
            && !"null".equals(sKeyRedis.trim())
            && sKeyRedis.length() > 15) {
          if (!asFieldName.isEmpty() && n < asFieldName.size()) {
            // String sDescription = asFieldName.get((asFieldName.size() - 1) - n);
            String sDescription = asFieldName.get(n);
            LOG.info("(sDescription={})", sDescription);
            String sID_Field = asFieldID.get(n);
            LOG.info("(sID_Field={})", sID_Field);

            byte[] aByteFile;
            ByteArrayMultipartFile oByteArrayMultipartFile = null;
            try {
              aByteFile = oBytesDataInmemoryStorage.getBytes(sKeyRedis);
              oByteArrayMultipartFile = getByteArrayMultipartFileFromStorageInmemory(aByteFile);
            } catch (ClassNotFoundException | IOException | RecordInmemoryException e1) {
              throw new ActivitiException(e1.getMessage(), e1);
            }
            if (oByteArrayMultipartFile != null) {
              String sFileName = null;
              try {
                sFileName =
                    new String(oByteArrayMultipartFile.getOriginalFilename().getBytes(), "UTF-8");
              } catch (java.io.UnsupportedEncodingException oException) {
                LOG.error("error on getting sFileName: {}", oException.getMessage());
                throw new ActivitiException(oException.getMessage(), oException);
              }
              LOG.info("(sFileName={})", sFileName);

              // ===
              InputStream oInputStream = null;
              try {
                oInputStream = oByteArrayMultipartFile.getInputStream();
              } catch (Exception e) {
                throw new ActivitiException(e.getMessage(), e);
              }
              Attachment oAttachment =
                  oExecution
                      .getEngineServices()
                      .getTaskService()
                      .createAttachment(
                          oByteArrayMultipartFile.getContentType()
                              + ";"
                              + oByteArrayMultipartFile.getExp(),
                          oTask.getId(),
                          oExecution.getProcessInstanceId(),
                          sFileName,
                          sDescription,
                          oInputStream);

              if (oAttachment != null) {
                String nID_Attachment = oAttachment.getId();
                // LOG.info("(nID_Attachment={})", nID_Attachment);
                LOG.info(
                    "Try set variable(sID_Field={}) with the value(nID_Attachment={}), for new attachment...",
                    sID_Field,
                    nID_Attachment);
                oExecution
                    .getEngineServices()
                    .getRuntimeService()
                    .setVariable(oExecution.getProcessInstanceId(), sID_Field, nID_Attachment);
                LOG.info(
                    "Finished setting new value for variable with attachment (sID_Field={})",
                    sID_Field);
              } else {
                LOG.error("Can't add attachment to (oTask.getId()={})", oTask.getId());
              }
              // ===

            } else {
              LOG.error("oByteArrayMultipartFile==null!  (sKeyRedis={})", sKeyRedis);
            }
          } else {
            LOG.error("asFieldName has nothing! (asFieldName={})", asFieldName);
          }
        } else {
          LOG.error("Invalid Redis Key!!! (sKeyRedis={})", sKeyRedis);
        }
        n++;
      }
    }

    scanExecutionOnQueueTickets(oExecution, oFormData); // , oTask);//startformData

    /*LOG.info("SCAN:queueData");
    asFieldID = getListField_QueueDataFormType(formData);
    LOG.info("asFieldID="+asFieldID.toString());
    asFieldValue = getVariableValues(execution, asFieldID);
    LOG.info("asFieldValue="+asFieldValue.toString());
    //asFieldName = getListCastomFieldName(formData);
    //LOG.info("asFieldName="+asFieldName.toString());
    if (!asFieldValue.isEmpty()) {
    String sValue = asFieldValue.get(0);
    LOG.info("sValue=" + sValue);
    long nID_FlowSlotTicket=0;
    int nAt=sValue.indexOf(":");
    int nTo=sValue.indexOf(",");
    String s=sValue.substring(nAt+1,nTo);
    LOG.info("s=" + s);
    try{
    nID_FlowSlotTicket = Long.valueOf(s);
    LOG.info("Ok!");
    }catch(Exception oException){
    LOG.error(oException.getMessage());
    nID_FlowSlotTicket=1;
    }
    LOG.info("nID_FlowSlotTicket=" + nID_FlowSlotTicket);

    try{


    //                FlowSlotTicket oFlowSlotTicket = baseEntityDao.getById(FlowSlotTicket.class, nID_FlowSlotTicket);
    //                if (oFlowSlotTicket == null) {
    //                    LOG.error("FlowSlotTicket with id=" + nID_FlowSlotTicket + " is not found!");
    //                }else{
    //                    long nID_FlowSlot=oFlowSlotTicket.getoFlowSlot().getId();
    //                    LOG.error("nID_FlowSlot="+nID_FlowSlot);
    //                    long nID_Subject = oFlowSlotTicket.getnID_Subject();
    //                    LOG.error("nID_Subject="+nID_Subject);
    //                    long nID_Task_Activiti = 1; //TODO set real ID!!!
    //                    oFlowSlotTicket.setnID_Task_Activiti(nID_Task_Activiti);
    //                    baseEntityDao.saveOrUpdate(oFlowSlotTicket);
    //                    LOG.info("JSON:" + JsonRestUtils.toJsonResponse(new SaveFlowSlotTicketResponse(oFlowSlotTicket.getId())));
    //                }

    }catch(Exception oException){
    LOG.error(oException.getMessage());
    }

    }*/

  }
Example #5
0
  public Atm() // constructor
        // sets the customer array to that found in the file if the file exists
      {
    try {
      // Set cross-platform Java L&F (also called "Metal")
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    if (logFile.exists()) {
      try {
        adminLogs = returnLog("p2.log");
        if (!adminLogs.isEmpty()) {
          // there may be customer data but perhaps no transactions yet.
          ArrayList<Integer> allTransactions = new ArrayList<>(100);
          for (AdminLog a : adminLogs) {

            int transaction = a.getTransactionID();
            ;
            allTransactions.add(transaction);
          }
          transaction_counter = Collections.max(allTransactions) + 1;
        }
      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    }

    if (DBfile.exists()) {
      try {

        cust = returnSavedData("p2.dat");

        // sets the starting ID to the max of all the IDs stored in the file.
        allIDs = new ArrayList<Integer>(100);
        ArrayList<Integer> allAccounts = new ArrayList<>();
        for (Customer customer : cust) {
          String idString = customer.returnID();
          int id = Integer.parseInt(idString);
          allIDs.add(id);
          int accountNumber = customer.returnMaxAccount();
          allAccounts.add(accountNumber);
        }
        // checks to see if the customer has even made any accounts, if not, max accounts will be
        // set at 1001
        if (starting_account_number != 1) {
          starting_account_number = Collections.max(allAccounts) + 1;
        }
        starting_customer_number = Collections.max(allIDs) + 1;

      } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
      }
    } else {
      cust = new ArrayList<>(100);
      // creates the file if it does not exist
      try {
        saveFile(cust, DBfile);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    interest_rate = 5;
  }