Ejemplo n.º 1
0
  protected boolean _setDevice(Device device, String ipAddress, int clientPort) {

    /* valid device? */
    if (device == null) {
      return false;
    }

    /* validate ID address */
    DataTransport dataXPort = device.getDataTransport();
    if ((ipAddress != null) && !dataXPort.isValidIPAddress(ipAddress)) {
      Print.logError(
          "Invalid IPAddr: "
              + device.getAccountID()
              + "/"
              + device.getDeviceID()
              + " Found="
              + ipAddress
              + " Expect="
              + dataXPort.getIpAddressValid());
      return false;
    }

    /* update device */
    this.device = device;
    this.dataXPort = dataXPort;
    this.dataXPort.setIpAddressCurrent(ipAddress); // FLD_ipAddressCurrent
    this.dataXPort.setRemotePortCurrent(clientPort); // FLD_remotePortCurrent
    this.dataXPort.setDeviceCode(this.getDeviceCode()); // FLD_deviceCode
    this.device.setLastTotalConnectTime(DateTime.getCurrentTimeSec()); // FLD_lastTotalConnectTime

    /* ok */
    return true;
  }
Ejemplo n.º 2
0
 /**
  * Set the AE title for this Network AE.
  *
  * @param aet A String containing the AE title.
  */
 public void setAETitle(String aet) {
   if (aet.isEmpty()) throw new IllegalArgumentException("AE title cannot be empty");
   Device device = this.device;
   if (device != null && this.AETitle != null) device.removeApplicationEntity(this.AETitle);
   this.AETitle = aet;
   if (device != null) device.addApplicationEntity(this);
 }
Ejemplo n.º 3
0
  public DimseRQHandler getDimseRQHandler() {
    DimseRQHandler handler = dimseRQHandler;
    if (handler != null) return handler;

    Device device = this.device;
    return device != null ? device.getDimseRQHandler() : null;
  }
Ejemplo n.º 4
0
 public void monitor() {
   final Device d = getDevice(uuid);
   monitor =
       new Thread(
           new Runnable() {
             @Override
             public void run() {
               String id = data.get("InstanceID");
               while (active && !"STOPPED".equals(data.get("TransportState"))) {
                 UPNPHelper.sleep(1000);
                 //						if (DEBUG) LOGGER.debug("InstanceID: " + id);
                 for (ActionArgumentValue o : getPositionInfo(d, id)) {
                   data.put(o.getArgument().getName(), o.toString());
                   //							if (DEBUG) LOGGER.debug(o.getArgument().getName() + ": " +
                   // o.toString());
                 }
                 alert();
               }
               if (!active) {
                 data.put("TransportState", "STOPPED");
                 alert();
               }
             }
           },
           "UPNP-" + d.getDetails().getFriendlyName());
   monitor.start();
 }
Ejemplo n.º 5
0
 public static boolean isNonRenderer(InetAddress socket) {
   Device d = getDevice(socket);
   boolean b = (d != null && !isMediaRenderer(d));
   if (b) {
     LOGGER.debug("Device at {} is {}: {}", socket, d.getType(), d.toString());
   }
   return b;
 }
Ejemplo n.º 6
0
 protected synchronized boolean addRenderer(Device d) {
   if (d != null) {
     String uuid = getUUID(d);
     if (isMediaRenderer(d) && rendererFound(d, uuid) != null) {
       LOGGER.debug("Adding device: {} {}", d.getType(), d.toString());
       rendererMap.mark(uuid, ACTIVE, true);
       subscribeAll(d, uuid);
       rendererReady(uuid);
       return true;
     }
   }
   return false;
 }
  @Transactional(propagation = Propagation.SUPPORTS)
  public boolean hasAccessToDevice(AccessKey accessKey, String deviceGuid) {
    Set<AccessKeyPermission> permissions = accessKey.getPermissions();
    Set<String> allowedDevices = new HashSet<>();
    Set<Long> allowedNetworks = new HashSet<>();

    User accessKeyUser = userService.findUserWithNetworks(accessKey.getUser().getId());
    Set<AccessKeyPermission> toRemove = new HashSet<>();

    Device device =
        genericDAO
            .createNamedQuery(Device.class, "Device.findByUUID", of(CacheConfig.refresh()))
            .setParameter("guid", deviceGuid)
            .getSingleResult();

    for (AccessKeyPermission currentPermission : permissions) {
      if (currentPermission.getDeviceGuidsAsSet() == null) {
        allowedDevices.add(null);
      } else {
        if (!currentPermission.getDeviceGuidsAsSet().contains(deviceGuid)) {
          toRemove.add(currentPermission);
        } else {
          allowedDevices.addAll(currentPermission.getDeviceGuidsAsSet());
        }
      }
      if (currentPermission.getNetworkIdsAsSet() == null) {
        allowedNetworks.add(null);
      } else {
        if (device.getNetwork() != null) {
          if (!currentPermission.getNetworkIdsAsSet().contains(device.getNetwork().getId())) {
            toRemove.add(currentPermission);
          } else {
            allowedNetworks.addAll(currentPermission.getNetworkIdsAsSet());
          }
        }
      }
    }
    permissions.removeAll(toRemove);
    boolean hasAccess;
    hasAccess =
        allowedDevices.contains(null)
            ? userService.hasAccessToDevice(accessKeyUser, device.getGuid())
            : allowedDevices.contains(device.getGuid())
                && userService.hasAccessToDevice(accessKeyUser, device.getGuid());

    hasAccess =
        hasAccess && allowedNetworks.contains(null)
            ? accessKeyUser.isAdmin() || accessKeyUser.getNetworks().contains(device.getNetwork())
            : (accessKeyUser.isAdmin() || accessKeyUser.getNetworks().contains(device.getNetwork()))
                && allowedNetworks.contains(device.getNetwork().getId());

    return hasAccess;
  }
Ejemplo n.º 8
0
 public static Map<String, String> getDeviceDetails(Device d) {
   if (d == null) {
     return null;
   }
   DeviceDetails dev = d.getDetails();
   ManufacturerDetails man = dev.getManufacturerDetails();
   ModelDetails model = dev.getModelDetails();
   LinkedHashMap<String, String> details = new LinkedHashMap<>();
   details.put("friendlyName", dev.getFriendlyName());
   details.put("address", getURL(d).getHost());
   details.put("udn", getUUID(d));
   Object detail;
   if ((detail = man.getManufacturer()) != null) {
     details.put("manufacturer", (String) detail);
   }
   if ((detail = model.getModelName()) != null) {
     details.put("modelName", (String) detail);
   }
   if ((detail = model.getModelNumber()) != null) {
     details.put("modelNumber", (String) detail);
   }
   if ((detail = model.getModelDescription()) != null) {
     details.put("modelDescription", (String) detail);
   }
   if ((detail = man.getManufacturerURI()) != null) {
     details.put("manufacturerURL", detail.toString());
   }
   if ((detail = model.getModelURI()) != null) {
     details.put("modelURL", detail.toString());
   }
   return details;
 }
Ejemplo n.º 9
0
 public static List<String> getServiceNames(Device d) {
   ArrayList<String> services = new ArrayList<>();
   for (Service s : d.getServices()) {
     services.add(s.getServiceId().getId());
   }
   return services;
 }
Ejemplo n.º 10
0
 protected String getSmsEmailAddress(Device device) {
   if (device == null) {
     return null;
   }
   String toEmail = device.getSmsEmail();
   return toEmail;
 }
Ejemplo n.º 11
0
 protected String getSmsPhoneNumber(Device device) {
   if (device == null) {
     return null;
   }
   String smsPhone = device.getSimPhoneNumber();
   return smsPhone;
 }
Ejemplo n.º 12
0
  public void addConnection(Connection conn) {
    if (conn.getProtocol() != Connection.Protocol.DICOM)
      throw new IllegalArgumentException("protocol != DICOM - " + conn.getProtocol());

    if (device != null && device != conn.getDevice())
      throw new IllegalStateException(conn + " not contained by Device: " + device.getDeviceName());
    connections.add(conn);
  }
Ejemplo n.º 13
0
 public static boolean isMediaRenderer(Device d) {
   String t = d.getType().getType();
   for (DeviceType r : mediaRendererTypes) {
     if (r.getType().equals(t)) {
       return true;
     }
   }
   return false;
 }
  /**
   * This uses a native query because you can't use the DATE() function in MySQL in a JPA query
   *
   * @param start startDate
   * @param end endDate end date ( uses the whole day via DateUtil.getNextDay() )
   * @param c Company
   * @param campaign Campaign (optional)
   * @param device Device (optional)
   * @return
   */
  @Override
  public List<BluetoothFileSendSummary> getBluetoothFileSendSummaryFromBluetoothSend(
      Date start, Date end, Company company, Campaign campaign, Device device) {

    int count = 4;
    HashMap<Integer, Object> parameters = new HashMap<Integer, Object>();

    String query =
        "SELECT DATE(event_date), file, count(*) "
            + "FROM bluetooth_send "
            + "WHERE send_status = 1 "
            + "AND company_id = ?1 "
            + "AND event_date BETWEEN ?2 AND ?3 ";
    if (campaign != null) {
      query += "AND campaign_id = ?" + count + " ";
      parameters.put(count, campaign.getId());
      count++;
    }
    if (device != null) {
      query += "AND device_id = ?" + count + " ";
      parameters.put(count, device.getId());
      count++;
    }

    query += "GROUP BY file, DATE(event_date) ORDER BY DATE(event_date)";

    Query q = em.createNativeQuery(query);
    q.setParameter(1, company.getId());
    q.setParameter(2, start);
    q.setParameter(3, DateUtil.getNextDay(end));

    for (Map.Entry<Integer, Object> entry : parameters.entrySet()) {
      Integer position = entry.getKey();
      Object param = entry.getValue();
      q.setParameter(position, param);
    }

    List<BluetoothFileSendSummary> results = new ArrayList<BluetoothFileSendSummary>();

    List<Object[]> result = q.getResultList();
    for (Object[] object : result) {
      Date eventDate = (Date) object[0];
      String file = (String) object[1];
      Long sendCount = (Long) object[2];

      BluetoothFileSendSummary item = new BluetoothFileSendSummary();
      item.setEventDate(eventDate);
      item.setFile(file);
      item.setSendCount(sendCount);
      item.setCompany(company);
      item.setCampaign(campaign);
      item.setDevice(device);

      results.add(item);
    }
    return results;
  }
Ejemplo n.º 15
0
 /**
  * Set the device that is identified by this application entity.
  *
  * @param device The owning <code>Device</code>.
  */
 public void setDevice(Device device) {
   if (device != null) {
     if (this.device != null && this.device != device)
       throw new IllegalStateException("already owned by " + this.device.getDeviceName());
     for (Connection conn : connections)
       if (conn.getDevice() != device)
         throw new IllegalStateException(conn + " not owned by " + device.getDeviceName());
   }
   this.device = device;
 }
Ejemplo n.º 16
0
  /* return icon name */
  public static String getIconName(Device device, int statusCode, BasicPrivateLabel pl) {

    /* device code */
    if (device != null) {
      StatusCode code = device.getStatusCode(statusCode);
      if (code != null) {
        return code.getIconName();
      }
    }

    /* default */
    return StatusCodes.GetIconName(statusCode, pl);
  }
Ejemplo n.º 17
0
 protected void subscribeAll(Device d, String uuid) {
   String name = getFriendlyName(d);
   int ctrl = 0;
   for (Service s : d.getServices()) {
     String sid = s.getServiceId().getId();
     LOGGER.debug("Subscribing to " + sid + " service on " + name);
     if (sid.contains("AVTransport")) {
       ctrl |= AVT;
     } else if (sid.contains("RenderingControl")) {
       ctrl |= RC;
     }
     upnpService.getControlPoint().execute(new SubscriptionCB(s));
   }
   rendererMap.mark(uuid, RENEW, false);
   rendererMap.mark(uuid, CONTROLS, ctrl);
 }
Ejemplo n.º 18
0
 protected String getStringProperty(Device device, String key, String dft) {
   DCServerConfig dcs =
       (device != null) ? DCServerFactory.getServerConfig(device.getDeviceCode()) : null;
   String prop = null;
   if (dcs != null) {
     prop = dcs.getStringProperty(key, dft);
     Print.logInfo("DCServerConfig property '" + key + "' ==> " + prop);
     if (StringTools.isBlank(prop) && RTConfig.hasProperty(key)) {
       Print.logInfo("(RTConfig property '" + key + "' ==> " + RTConfig.getString(key, "") + ")");
     }
   } else {
     prop = RTConfig.getString(key, dft);
     Print.logInfo("RTConfig property '" + key + "' ==> " + prop);
   }
   return prop;
 }
Ejemplo n.º 19
0
  // Convenience functions for sending various upnp service requests
  public static ActionInvocation send(
      final Device dev, String instanceID, String service, String action, String... args) {
    Service svc = dev.findService(ServiceId.valueOf("urn:upnp-org:serviceId:" + service));
    final String uuid = getUUID(dev);
    if (svc != null) {
      Action x = svc.getAction(action);
      String name = getFriendlyName(dev);
      boolean log = !action.equals("GetPositionInfo");
      if (x != null) {
        ActionInvocation a = new ActionInvocation(x);
        a.setInput("InstanceID", instanceID);
        for (int i = 0; i < args.length; i += 2) {
          a.setInput(args[i], args[i + 1]);
        }
        if (log) {
          LOGGER.debug("Sending upnp {}.{} {} to {}[{}]", service, action, args, name, instanceID);
        }
        new ActionCallback(a, upnpService.getControlPoint()) {
          @Override
          public void success(ActionInvocation invocation) {
            rendererMap.mark(uuid, ACTIVE, true);
          }

          @Override
          public void failure(
              ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            LOGGER.debug("Action failed: {}", defaultMsg);
            rendererMap.mark(uuid, ACTIVE, false);
          }
        }.run();

        if (log) {
          for (ActionArgumentValue arg : a.getOutput()) {
            LOGGER.debug(
                "Received from {}[{}]: {}={}",
                name,
                instanceID,
                arg.getArgument().getName(),
                arg.toString());
          }
        }
        return a;
      }
    }
    return null;
  }
Ejemplo n.º 20
0
 public static DBFactory<StatusCode> getFactory() {
   if (factory == null) {
     factory =
         DBFactory.createDBFactory(
             StatusCode.TABLE_NAME(),
             StatusCode.FieldInfo,
             DBFactory.KeyType.PRIMARY,
             StatusCode.class,
             StatusCode.Key.class,
             true /*editable*/,
             true /*viewable*/);
     factory.addParentTable(Account.TABLE_NAME());
     factory.addParentTable(Device.TABLE_NAME());
     factory.setFieldDefaultValue(FLD_deviceID, ALL_DEVICES);
   }
   return factory;
 }
Ejemplo n.º 21
0
  /* Return status code description */
  public static String getDescription(
      Device device, int statusCode, BasicPrivateLabel bpl, String dftDesc) {

    /* device code */
    if (device != null) {
      StatusCode code = device.getStatusCode(statusCode);
      if (code != null) {
        return code.getDescription();
      }
    }

    /* default */
    if (!StringTools.isBlank(dftDesc)) {
      return dftDesc;
    } else {
      return StatusCodes.GetDescription(statusCode, bpl);
    }
  }
Ejemplo n.º 22
0
 public static String getDeviceIcon(Device d, int maxHeight) {
   URL base = getURL(d);
   Icon icon = null;
   String url = null;
   int maxH = maxHeight == 0 ? 99999 : maxHeight, height = 0;
   for (Icon i : d.getIcons()) {
     int h = i.getHeight();
     if (h < maxH && h > height) {
       icon = i;
       height = h;
     }
   }
   try {
     url = icon != null ? new URL(base, icon.getUri().toString()).toString() : null;
   } catch (Exception e) {
   }
   LOGGER.debug("Device icon: " + url);
   return url;
 }
Ejemplo n.º 23
0
 public Device copy() {
   Device dst = new Device();
   dst.type = type == null ? null : type.copy();
   dst.manufacturer = manufacturer == null ? null : manufacturer.copy();
   dst.model = model == null ? null : model.copy();
   dst.version = version == null ? null : version.copy();
   dst.expiry = expiry == null ? null : expiry.copy();
   dst.identity = identity == null ? null : identity.copy(dst);
   dst.owner = owner == null ? null : owner.copy();
   dst.assignedId = new ArrayList<Identifier>();
   for (Identifier i : assignedId) dst.assignedId.add(i.copy());
   dst.location = location == null ? null : location.copy();
   dst.patient = patient == null ? null : patient.copy();
   dst.contact = new ArrayList<Contact>();
   for (Contact i : contact) dst.contact.add(i.copy());
   dst.url = url == null ? null : url.copy();
   return dst;
 }
Ejemplo n.º 24
0
 public static String getFriendlyName(Device d) {
   return d.getDetails().getFriendlyName();
 }
Ejemplo n.º 25
0
 public static String getUUID(Device d) {
   return d.getIdentity().getUdn().toString();
 }
Ejemplo n.º 26
0
 protected String getFromEmailAddress(Device device) {
   if (device == null) {
     return null;
   }
   return CommandPacketHandler.getFromEmailCommand(device.getAccount());
 }
Ejemplo n.º 27
0
 public static URL getURL(Device d) {
   return d instanceof RemoteDevice
       ? ((RemoteDevice) d).getIdentity().getDescriptorURL()
       : d.getDetails().getBaseURL();
 }
Ejemplo n.º 28
0
 void reconfigure(ApplicationEntity src) {
   setApplicationEntityAttributes(src);
   device.reconfigureConnections(connections, src.connections);
   reconfigureTransferCapabilities(src);
   reconfigureAEExtensions(src);
 }
Ejemplo n.º 29
0
 /**
  * Determine whether or not this network AE is installed on a network.
  *
  * @return A Boolean value. True if the AE is installed on a network. If not present, information
  *     about the installed status of the AE is inherited from the device
  */
 public boolean isInstalled() {
   return device != null
       && device.isInstalled()
       && (aeInstalled == null || aeInstalled.booleanValue());
 }
Ejemplo n.º 30
0
  public static void main(String argv[]) {
    DBConfig.cmdLineInit(argv, true); // main
    String accountID = RTConfig.getString(ARG_ACCOUNT, "");
    String deviceID = RTConfig.getString(ARG_DEVICE, "");
    int statusCode = RTConfig.getInt(ARG_CODE, 0);
    boolean anyCode = true; // RTConfig.hasProperty(ARG_ECODE);

    /* account-id specified? */
    if (StringTools.isBlank(accountID)) {
      Print.logError("Account-ID not specified.");
      usage();
    }

    /* get account */
    Account account = null;
    try {
      account = Account.getAccount(accountID); // may throw DBException
      if (account == null) {
        Print.logError("Account-ID does not exist: " + accountID);
        usage();
      }
    } catch (DBException dbe) {
      Print.logException("Error loading Account: " + accountID, dbe);
      // dbe.printException();
      System.exit(99);
    }

    /* device-id specified? */
    if (StringTools.isBlank(deviceID) || deviceID.startsWith("/")) {
      deviceID = ALL_DEVICES;
    }

    /* check device existance */
    if (!deviceID.equals(ALL_DEVICES)) {
      try {
        Device device = Device.getDevice(account, deviceID); // may throw DBException
        if (device == null) {
          Print.logError("Device-ID does not exist: " + accountID + " / " + deviceID);
          usage();
        }
      } catch (DBException dbe) {
        Print.logException("Error loading Device: " + accountID + " / " + deviceID, dbe);
        System.exit(99);
      }
    }

    /* status-code specified? */
    if ((statusCode > 0)
        && !anyCode
        && !StatusCodes.IsValid(statusCode, account.getPrivateLabel())) {
      Print.logError("Invalid Status Code specified.");
      usage();
    }

    /* statusCode specified? */
    if (statusCode <= 0) {
      Print.logError("StatusCode not specified.");
      usage();
    }

    /* statusCode exists? */
    boolean statusCodeExists = false;
    try {
      statusCodeExists = StatusCode.exists(accountID, deviceID, statusCode);
    } catch (DBException dbe) {
      Print.logError(
          "Error determining if StatusCode exists: "
              + accountID
              + "/"
              + deviceID
              + "/"
              + statusCode);
      System.exit(99);
    }

    /* option count */
    int opts = 0;

    /* delete */
    if (RTConfig.getBoolean(ARG_DELETE, false)) {
      opts++;
      if (!statusCodeExists) {
        Print.logWarn(
            "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode);
        Print.logWarn("Continuing with delete process ...");
      }
      try {
        StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, statusCode);
        scKey.delete(true); // also delete dependencies (if any)
        Print.logInfo("StatusCode deleted: " + accountID + "/" + deviceID + "/" + statusCode);
        statusCodeExists = false;
      } catch (DBException dbe) {
        Print.logError(
            "Error deleting StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
        dbe.printException();
        System.exit(99);
      }
      System.exit(0);
    }

    /* create */
    if (RTConfig.getBoolean(ARG_CREATE, false)) {
      opts++;
      if (statusCodeExists) {
        Print.logWarn(
            "StatusCode already exists: " + accountID + "/" + deviceID + "/" + statusCode);
      } else {
        try {
          StatusCode.createNewStatusCode(account, deviceID, statusCode);
          Print.logInfo("Created StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          statusCodeExists = true;
        } catch (DBException dbe) {
          Print.logError(
              "Error creating StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          dbe.printException();
          System.exit(99);
        }
      }
    }

    /* edit */
    if (RTConfig.getBoolean(ARG_EDIT, false)) {
      opts++;
      if (!statusCodeExists) {
        Print.logError(
            "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode);
      } else {
        try {
          StatusCode sc =
              StatusCode.getStatusCode(account, deviceID, statusCode); // may throw DBException
          DBEdit editor = new DBEdit(sc);
          editor.edit(); // may throw IOException
        } catch (IOException ioe) {
          if (ioe instanceof EOFException) {
            Print.logError("End of input");
          } else {
            Print.logError("IO Error");
          }
        } catch (DBException dbe) {
          Print.logError(
              "Error editing StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          dbe.printException();
        }
      }
      System.exit(0);
    }

    /* list */
    if (RTConfig.hasProperty(ARG_LIST)) {
      opts++;
      String listType = RTConfig.getString(ARG_LIST, null);
      // TODO: complete ...
    }

    /* no options specified */
    if (opts == 0) {
      Print.logWarn("Missing options ...");
      usage();
    }
  }