Beispiel #1
0
 public Member addMember(
     PerunSession sess, Group group, Member member, MembershipType type, int sourceGroupId)
     throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException,
         WrongReferenceAttributeValueException {
   // TODO already member exception
   member.setMembershipType(type);
   try {
     jdbc.update(
         "insert into groups_members (group_id, member_id, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid, membership_type, source_group_id) "
             + "values (?,?,?,"
             + Compatibility.getSysdate()
             + ",?,"
             + Compatibility.getSysdate()
             + ",?,?,?,?)",
         group.getId(),
         member.getId(),
         sess.getPerunPrincipal().getActor(),
         sess.getPerunPrincipal().getActor(),
         sess.getPerunPrincipal().getUserId(),
         sess.getPerunPrincipal().getUserId(),
         type.getCode(),
         sourceGroupId);
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
   return member;
 }
Beispiel #2
0
  public List<Group> getGroups(PerunSession sess, Vo vo) throws InternalErrorException {
    try {
      return jdbc.query(
          "select  "
              + groupMappingSelectQuery
              + " from groups where vo_id=? order by "
              + Compatibility.orderByBinary("groups.name" + Compatibility.castToVarchar()),
          GROUP_MAPPER,
          vo.getId());

    } catch (RuntimeException ex) {
      throw new InternalErrorException(ex);
    }
  }
Beispiel #3
0
 public List<User> getGroupUsers(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + UsersManagerImpl.userMappingSelectQuery
             + " from groups_members join members on members.id=member_id join "
             + "users on members.user_id=users.id where group_id=? order by "
             + Compatibility.orderByBinary("users.last_name")
             + ", "
             + Compatibility.orderByBinary("users.first_name"),
         UsersManagerImpl.USER_MAPPER,
         group.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
Beispiel #4
0
  public Group updateGroupName(PerunSession sess, Group group) throws InternalErrorException {
    Utils.notNull(group.getName(), "group.getName()");

    // Get the group stored in the DB
    Group dbGroup;
    try {
      dbGroup = this.getGroupById(sess, group.getId());
    } catch (GroupNotExistsException e) {
      throw new InternalErrorException("Group existence was checked at the higher level", e);
    }

    if (!dbGroup.getName().equals(group.getName())) {
      dbGroup.setName(group.getName());
      try {
        jdbc.update(
            "update groups set name=?,modified_by=?, modified_by_uid=?, modified_at="
                + Compatibility.getSysdate()
                + " where id=?",
            dbGroup.getName(),
            sess.getPerunPrincipal().getActor(),
            sess.getPerunPrincipal().getUserId(),
            dbGroup.getId());
      } catch (RuntimeException e) {
        throw new InternalErrorException(e);
      }
    }
    return dbGroup;
  }
Beispiel #5
0
 public List<Group> getSubGroups(PerunSession sess, Group parentGroup)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups where groups.parent_group_id=? "
             + "order by "
             + Compatibility.orderByBinary("groups.name" + Compatibility.castToVarchar()),
         GROUP_MAPPER,
         parentGroup.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
Beispiel #6
0
  /** Shows a Dialog displaying the selected indices and then shows the MIDlet main view. */
  public void showSelectedDialog() {
    String text = (getSelectedIndices().length == 0 ? "No selected items." : "");
    for (int i = 0; i < getSelectedIndices().length; i++) {
      text += "List item " + (getSelectedIndices()[i] + 1) + " selected.\n";
    }

    Dialog.show(
        Compatibility.toLowerCaseIfFT("Selected"),
        text,
        new Command(Compatibility.toUpperCaseIfFT("Continue")),
        null,
        Dialog.TYPE_INFO,
        null,
        1500L);

    DemoMidlet.getMainForm().show();
  }
Beispiel #7
0
  public List<Member> getGroupMembers(
      PerunSession sess,
      Group group,
      List<Status> statuses,
      boolean excludeStatusInsteadOfIncludeStatus)
      throws InternalErrorException {
    try {
      MapSqlParameterSource parameters = new MapSqlParameterSource();
      List<Integer> statusesCodes = new ArrayList<Integer>();
      for (Status status : statuses) {
        statusesCodes.add(status.getCode());
      }
      parameters.addValue("statuses", statusesCodes);
      parameters.addValue("group_id", group.getId());

      if (excludeStatusInsteadOfIncludeStatus) {
        // Exclude members with one of the status
        return this.namedParameterJdbcTemplate.query(
            "select "
                + MembersManagerImpl.memberMappingSelectQuery
                + ", groups_members.membership_type as membership_type from groups_members join members on members.id=groups_members.member_id "
                + " where groups_members.group_id=:group_id and members.status"
                + Compatibility.castToInteger()
                + " not in (:statuses)",
            parameters,
            MembersManagerImpl.MEMBER_MAPPER);
      } else {
        // Include members with one of the status
        return this.namedParameterJdbcTemplate.query(
            "select "
                + MembersManagerImpl.memberMappingSelectQuery
                + ", groups_members.membership_type as membership_type from groups_members join members on members.id=groups_members.member_id "
                + " where groups_members.group_id=:group_id and members.status"
                + Compatibility.castToInteger()
                + " in (:statuses)",
            parameters,
            MembersManagerImpl.MEMBER_MAPPER);
      }
    } catch (EmptyResultDataAccessException e) {
      return new ArrayList<Member>();
    } catch (RuntimeException e) {
      throw new InternalErrorException(e);
    }
  }
Beispiel #8
0
 @SuppressWarnings("deprecation")
 public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
   android.hardware.Camera.Parameters parameters = camera.getParameters();
   List list;
   float f;
   list = Compatibility.getSupportedPreviewSizes(parameters);
   f = (float) j / (float) k;
   float f1;
   int l;
   int i1;
   f1 = 0.0F;
   l = 0;
   i1 = 0;
   Iterator iterator = list.iterator();
   while (true) {
     if (iterator.hasNext()) {
       android.hardware.Camera.Size size = (android.hardware.Camera.Size) iterator.next();
       float f2 = (float) size.width / (float) size.height;
       if (f - f2 > f - f1) {
         continue; /* Loop/switch isn't completed */
       }
       if (size.width > j || size.width < l) {
         continue; /* Loop/switch isn't completed */
       }
       f1 = f2;
       try {
         l = size.width;
         i1 = size.height;
         continue; /* Loop/switch isn't completed */
       } catch (Exception exception1) {
       }
       try {
         parameters.setPreviewSize(480, 320);
         camera.setParameters(parameters);
         camera.startPreview();
         return;
       } catch (Exception exception) {
         exception.printStackTrace();
       }
       return;
     } else {
       if (l == 0 || i1 == 0) {
         l = 480;
         i1 = 320;
       }
       parameters.setPreviewSize(l, i1);
       break;
     }
   }
 }
 public String getUserAgent(Context ctx) {
   String userAgent = getPreferenceStringValue(SipConfigManager.USER_AGENT);
   if (userAgent.equalsIgnoreCase(CustomDistribution.getUserAgent())) {
     // If that's the official -not custom- user agent, send the release, the device and the api
     // level
     PackageInfo pinfo = getCurrentPackageInfos(ctx);
     if (pinfo != null) {
       userAgent +=
           "_"
               + android.os.Build.DEVICE
               + "-"
               + Compatibility.getApiLevel()
               + "/r"
               + pinfo.versionCode;
     }
   }
   return userAgent;
 }
 public static String read(Context paramContext, String[] paramArrayOfString) {
   for (; ; ) {
     try {
       localObject = Compatibility.getDropBoxServiceName();
       if (localObject == null) {
         return "N/A";
       }
       localObject = paramContext.getSystemService((String) localObject);
       localMethod1 =
           localObject.getClass().getMethod("getNextEntry", new Class[] {String.class, Long.TYPE});
       if (localMethod1 == null) {
         return "";
       }
       localTime = new Time();
       localTime.setToNow();
       localTime.minute -= ACRA.getConfig().dropboxCollectionMinutes();
       localTime.normalize(false);
       l1 = localTime.toMillis(false);
       paramContext = new ArrayList();
       if (ACRA.getConfig().includeDropBoxSystemTags()) {
         paramContext.addAll(Arrays.asList(SYSTEM_TAGS));
       }
       if ((paramArrayOfString != null) && (paramArrayOfString.length > 0)) {
         paramContext.addAll(Arrays.asList(paramArrayOfString));
       }
       if (paramContext.isEmpty()) {
         return "No tag configured for collection.";
       }
       paramArrayOfString = new StringBuilder();
       localIterator = paramContext.iterator();
     } catch (SecurityException paramContext) {
       Object localObject;
       Method localMethod1;
       Time localTime;
       long l1;
       Iterator localIterator;
       String str1;
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       return "N/A";
       Method localMethod2 =
           paramContext.getClass().getMethod("getText", new Class[] {Integer.TYPE});
       Method localMethod3 = paramContext.getClass().getMethod("getTimeMillis", (Class[]) null);
       Method localMethod4 = paramContext.getClass().getMethod("close", (Class[]) null);
       if (paramContext == null) {
         continue;
       }
       long l2 = ((Long) localMethod3.invoke(paramContext, (Object[]) null)).longValue();
       localTime.set(l2);
       paramArrayOfString.append("@").append(localTime.format2445()).append('\n');
       String str2 =
           (String) localMethod2.invoke(paramContext, new Object[] {Integer.valueOf(500)});
       if (str2 == null) {
         continue;
       }
       paramArrayOfString.append("Text: ").append(str2).append('\n');
       localMethod4.invoke(paramContext, (Object[]) null);
       paramContext = localMethod1.invoke(localObject, new Object[] {str1, Long.valueOf(l2)});
       continue;
       paramArrayOfString.append("Not Text!").append('\n');
       continue;
     } catch (NoSuchMethodException paramContext) {
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       continue;
       paramContext = paramArrayOfString.toString();
       return paramContext;
     } catch (IllegalArgumentException paramContext) {
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       continue;
     } catch (IllegalAccessException paramContext) {
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       continue;
     } catch (InvocationTargetException paramContext) {
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       continue;
     } catch (NoSuchFieldException paramContext) {
       Log.i(ACRA.LOG_TAG, "DropBoxManager not available.");
       continue;
     }
     if (!localIterator.hasNext()) {
       continue;
     }
     str1 = (String) localIterator.next();
     paramArrayOfString.append("Tag: ").append(str1).append('\n');
     paramContext = localMethod1.invoke(localObject, new Object[] {str1, Long.valueOf(l1)});
     if (paramContext != null) {
       continue;
     }
     paramArrayOfString.append("Nothing.").append('\n');
   }
 }
Beispiel #11
0
  int PromptAuth(long /*int*/ aChannel, int level, long /*int*/ authInfo, long /*int*/ _retval) {
    nsIAuthInformation auth = new nsIAuthInformation(authInfo);

    Browser browser = getBrowser();
    if (browser != null) {
      Mozilla mozilla = (Mozilla) browser.webBrowser;
      /*
       * Do not invoke the listeners if this challenge has been failed too many
       * times because a listener is likely giving incorrect credentials repeatedly
       * and will do so indefinitely.
       */
      if (mozilla.authCount++ < 3) {
        for (int i = 0; i < mozilla.authenticationListeners.length; i++) {
          AuthenticationEvent event = new AuthenticationEvent(browser);
          event.location = mozilla.lastNavigateURL;
          mozilla.authenticationListeners[i].authenticate(event);
          if (!event.doit) {
            XPCOM.memmove(_retval, new boolean[] {false});
            return XPCOM.NS_OK;
          }
          if (event.user != null && event.password != null) {
            nsEmbedString string = new nsEmbedString(event.user);
            int rc = auth.SetUsername(string.getAddress());
            if (rc != XPCOM.NS_OK) SWT.error(rc);
            string.dispose();
            string = new nsEmbedString(event.password);
            rc = auth.SetPassword(string.getAddress());
            if (rc != XPCOM.NS_OK) SWT.error(rc);
            string.dispose();
            XPCOM.memmove(_retval, new boolean[] {true});
            return XPCOM.NS_OK;
          }
        }
      }
    }

    /* no listener handled the challenge, so show an authentication dialog */

    String checkLabel = null;
    boolean[] checkValue = new boolean[1];
    String[] userLabel = new String[1], passLabel = new String[1];

    String title = SWT.getMessage("SWT_Authentication_Required"); // $NON-NLS-1$

    /* get initial username and password values */

    long /*int*/ ptr = XPCOM.nsEmbedString_new();
    int rc = auth.GetUsername(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    int length = XPCOM.nsEmbedString_Length(ptr);
    long /*int*/ buffer = XPCOM.nsEmbedString_get(ptr);
    char[] chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    userLabel[0] = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    ptr = XPCOM.nsEmbedString_new();
    rc = auth.GetPassword(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedString_Length(ptr);
    buffer = XPCOM.nsEmbedString_get(ptr);
    chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    passLabel[0] = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    /* compute the message text */

    ptr = XPCOM.nsEmbedString_new();
    rc = auth.GetRealm(ptr);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedString_Length(ptr);
    buffer = XPCOM.nsEmbedString_get(ptr);
    chars = new char[length];
    XPCOM.memmove(chars, buffer, length * 2);
    String realm = new String(chars);
    XPCOM.nsEmbedString_delete(ptr);

    nsIChannel channel = new nsIChannel(aChannel);
    long /*int*/[] uri = new long /*int*/[1];
    rc = channel.GetURI(uri);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    if (uri[0] == 0) Mozilla.error(XPCOM.NS_NOINTERFACE);

    nsIURI nsURI = new nsIURI(uri[0]);
    long /*int*/ host = XPCOM.nsEmbedCString_new();
    rc = nsURI.GetHost(host);
    if (rc != XPCOM.NS_OK) SWT.error(rc);
    length = XPCOM.nsEmbedCString_Length(host);
    buffer = XPCOM.nsEmbedCString_get(host);
    byte[] bytes = new byte[length];
    XPCOM.memmove(bytes, buffer, length);
    String hostString = new String(bytes);
    XPCOM.nsEmbedCString_delete(host);
    nsURI.Release();

    String message;
    if (realm.length() > 0 && hostString.length() > 0) {
      message =
          Compatibility.getMessage(
              "SWT_Enter_Username_and_Password", new String[] {realm, hostString}); // $NON-NLS-1$
    } else {
      message = ""; // $NON-NLS-1$
    }

    /* open the prompter */
    Shell shell = browser == null ? new Shell() : browser.getShell();
    PromptDialog dialog = new PromptDialog(shell);
    boolean[] result = new boolean[1];
    dialog.promptUsernameAndPassword(
        title, message, checkLabel, userLabel, passLabel, checkValue, result);

    XPCOM.memmove(_retval, result);
    if (result[0]) {
        /* User selected OK */
      nsEmbedString string = new nsEmbedString(userLabel[0]);
      rc = auth.SetUsername(string.getAddress());
      if (rc != XPCOM.NS_OK) SWT.error(rc);
      string.dispose();

      string = new nsEmbedString(passLabel[0]);
      rc = auth.SetPassword(string.getAddress());
      if (rc != XPCOM.NS_OK) SWT.error(rc);
      string.dispose();
    }

    return XPCOM.NS_OK;
  }
Beispiel #12
0
  public Group createGroup(PerunSession sess, Vo vo, Group group)
      throws GroupExistsException, InternalErrorException {
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.getName()");

    // Check if the group already exists
    if (group.getParentGroupId() == null) {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id IS NULL",
              group.getName(),
              vo.getId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id is [NULL]");
      }
    } else {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id=?",
              group.getName(),
              vo.getId(),
              group.getParentGroupId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id ["
                + group.getParentGroupId()
                + "]");
      }
    }

    // Check the group name, it can contain only a-Z0-9_- and space
    if (!group.getShortName().matches("^[- a-zA-Z.0-9_]+$")) {
      throw new InternalErrorException(
          new IllegalArgumentException(
              "Wrong group name, group name can contain only a-Z0-9.-_: and space characters. "
                  + group));
    }

    try {
      // Store the group into the DB
      int newId = Utils.getNewId(jdbc, "groups_id_seq");

      jdbc.update(
          "insert into groups (id, parent_group_id, name, dsc, vo_id, created_by,created_at,modified_by,modified_at,created_by_uid,modified_by_uid) "
              + "values (?,?,?,?,?,?,"
              + Compatibility.getSysdate()
              + ",?,"
              + Compatibility.getSysdate()
              + ",?,?)",
          newId,
          group.getParentGroupId(),
          group.getName(),
          group.getDescription(),
          vo.getId(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getUserId(),
          sess.getPerunPrincipal().getUserId());
      group.setId(newId);

      group.setVoId(vo.getId());

      return group;
    } catch (RuntimeException err) {
      throw new InternalErrorException(err);
    }
  }
Beispiel #13
0
/**
 * This is a base class for the list demos. It shows the selected items on a <code>Dialog</code>
 * when the list demo is exited, and it shows a confirmation query if Back button is pressed after
 * making changes to the list.
 */
public abstract class ListView extends Form {

  public static final int MAX_ITEMS = 10;
  public final String LIST_ITEM_TEXT = Compatibility.toLowerCaseIfFT("List item ");
  public static final String LONG_TEXT =
      ", Lorem ipsum dolor sit amet, consectetur adipiscing "
          + "elit. Phasellus vel neque pulvinar libero vestibulum malesua.";
  protected List list;
  protected int[] originalSelectedIndices; // used when abandoning changes
  private boolean confirmationQuery = false;

  public ListView() {
    setLayout(new BoxLayout(BoxLayout.Y_AXIS));

    // The list selection is stored every time the form is shown,
    // so we can see if changes have been made when the form is exited and
    // revert the changes if necessary.
    this.addShowListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            originalSelectedIndices = getSelectedIndices();
          }
        });

    // Add back command for exiting the Form.
    Command backCommand =
        new Command("Back") {
          public void actionPerformed(ActionEvent e) {
            back();
          }
        };
    setBackCommand(backCommand);
  }

  /** Shows a Dialog displaying the selected indices and then shows the MIDlet main view. */
  public void showSelectedDialog() {
    String text = (getSelectedIndices().length == 0 ? "No selected items." : "");
    for (int i = 0; i < getSelectedIndices().length; i++) {
      text += "List item " + (getSelectedIndices()[i] + 1) + " selected.\n";
    }

    Dialog.show(
        Compatibility.toLowerCaseIfFT("Selected"),
        text,
        new Command(Compatibility.toUpperCaseIfFT("Continue")),
        null,
        Dialog.TYPE_INFO,
        null,
        1500L);

    DemoMidlet.getMainForm().show();
  }

  /**
   * Returns an array containing the indices of selected list items
   *
   * @return Array containing the selected indices.
   */
  public int[] getSelectedIndices() {
    return new int[] {list.getSelectedIndex()};
  }

  /**
   * Sets the list items as selected / not selected based on the indices in an array.
   *
   * @param indices Array containing the selected indices.
   */
  public void setSelectedIndices(int[] indices) {
    if (indices.length > 0) {
      list.setSelectedIndex(indices[0]);
    }
  }

  /**
   * Turns on or off the confirmation query that is displayed when list is dismissed and changes
   * have been made to the list selection.
   *
   * @param value is the confirmation query shown.
   */
  public void setShowConfirmationQuery(boolean value) {
    confirmationQuery = value;
  }

  /**
   * Returns true if the list selections have changed after displaying the list. Otherwise returns
   * false.
   *
   * @return true if the list has changed, otherwise false.
   */
  public boolean hasChanged() {
    int[] s = getSelectedIndices();
    if (s.length != originalSelectedIndices.length) {
      return true;
    }
    for (int i = 0; i < s.length; i++) {
      if (s[i] != originalSelectedIndices[i]) {
        return true;
      }
    }
    return false;
  }

  /** Shows the ListDemo main view. Displays a confirmation query if needed. */
  protected void back() {
    if (hasChanged() && confirmationQuery) {
      int[] tmp = new int[originalSelectedIndices.length];
      System.arraycopy(originalSelectedIndices, 0, tmp, 0, tmp.length);
      if (Dialog.show("save changes", "Save changes made?", "Yes", "No")) {
        showSelectedDialog(); // Proceed with the changes
      } else {
        setSelectedIndices(tmp); // Abandon changes
        DemoMidlet.getMainForm().show();
      }
    } else {
      DemoMidlet.getMainForm().show();
    }
  }

  public void setTitle(String title) {
    super.setTitle(Compatibility.toLowerCaseIfFT(title));
  }

  public String toString() {
    return getTitle();
  }
}
Beispiel #14
0
 public void setTitle(String title) {
   super.setTitle(Compatibility.toLowerCaseIfFT(title));
 }