示例#1
0
  void process(AMStoreConnection dpConnection) throws AdminException {
    EntityUtils entityUtils = new EntityUtils();
    Map map = entityUtils.getEntityTypesMap(dpConnection);
    AMEntityType type = (AMEntityType) map.get(entityType);
    if (type == null) {
      throw new AdminException(bundle.getString("invalidEntity"));
    }
    String localizedName =
        entityUtils.getL10NAttributeName(dpConnection, type.getServiceName(), ENTITY_NAME);
    String args[] = {localizedName};

    String localizedStr = MessageFormat.format(bundle.getString("modifyEntity"), args);

    writer.println(bundle.getString("container") + " " + targetDN + "\n" + localizedStr);

    try {
      AMEntity entity = dpConnection.getEntity(entityDN);
      doLog(entity, AdminUtils.MODIFY_ENTITY_ATTEMPT, localizedName);
      entity.setAttributes(values);
      entity.store();
      //            doLog(entity, "modify-entity", localizedName);
      doLog(entity, AdminUtils.MODIFY_ENTITY, localizedName);
    } catch (AMException ame) {
      throw new AdminException(ame);
    } catch (SSOException ssoe) {
      throw new AdminException(ssoe);
    }
  }
 private StoreData buildStoreData(ClassMetaData cmd, ClassLoaderResolver clr) {
   String kindName = EntityUtils.getKindName(getIdentifierFactory(), cmd);
   DatastoreTable table = new DatastoreTable(kindName, this, cmd, clr, dba);
   StoreData sd = new MappedStoreData(cmd, table, true);
   registerStoreData(sd);
   // needs to be called after we register the store data to avoid stack overflow
   table.buildMapping();
   return sd;
 }
 public FieldManager getFieldManagerForResultProcessing(
     ObjectProvider op, Object resultSet, StatementClassMapping resultMappings) {
   ExecutionContext ec = op.getExecutionContext();
   Class<?> cls =
       ec.getClassLoaderResolver().classForName(op.getClassMetaData().getFullClassName());
   Object internalKey = EntityUtils.idToInternalKey(ec, cls, resultSet, true);
   // Need to provide this to the field manager in the form of the pk
   // of the type: Key, Long, encoded String, or unencoded String
   return new KeyOnlyFieldManager(internalKey);
 }
  @Override
  public Object fromByteBuffer(ByteBuffer byteBuffer) {
    if (byteBuffer == null || !byteBuffer.hasRemaining()) return null;

    Byte indicator = byteBuffer.get();
    Class<?> clazz = INDICATOR_BYTES_REV.get(indicator);

    if (clazz == null) throw new IllegalArgumentException("invalid indicator byte " + indicator);

    return EntityUtils.getSerializer(clazz).fromByteBuffer(byteBuffer);
  }
示例#5
0
 private static boolean isParent(IGroup groupToBeTested, IGroup parentGroup) {
   if (groupToBeTested.isGroup() == false) {
     // Very strange!
     return false;
   }
   if (groupToBeTested.isGroup() == false) {
     throw new IllegalArgumentException();
   }
   while (EntityUtils.groupRoot(groupToBeTested) == false) {
     if (groupToBeTested == parentGroup) {
       return true;
     }
     groupToBeTested = groupToBeTested.getParentContainer();
     if (groupToBeTested.isGroup() == false) {
       throw new IllegalStateException();
     }
   }
   return false;
 }
示例#6
0
  public void request1(String uri, int reqNum, int reqTerm) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    if (reqNum == 0) {
      System.out.println(
          String.format("request to %s infinite times with term '%d' ms", uri, reqTerm));
    } else {
      System.out.println(
          String.format("request to %s '%d' times with term '%d' ms", uri, reqNum, reqTerm));
    }

    int i = 0, tick = 0;
    HttpGet httpGet = new HttpGet(uri);
    CloseableHttpResponse response;
    HttpEntity entity;

    while (true) {
      usleep(reqTerm);
      tick = (int) (Math.random() * 10) % 2;
      if (tick == 0) {
        continue;
      }
      System.out.println("request " + httpGet.getURI());
      response = httpclient.execute(httpGet);
      System.out.println("--> response status  = " + response.getStatusLine());
      // response handler
      try {
        entity = response.getEntity();
        EntityUtils.consume(entity);
      } catch (Exception e) {
        System.out.println("  --> http fail:" + e.getMessage());
      } finally {
        // Thread.sleep(5000); //테스트에만 썼다. close 지연시키려고.
        response.close();
      }

      System.out.println("----------------------------------------");
      if (reqNum != 0 && reqNum < ++i) {
        break;
      }
    }
  }
  @SuppressWarnings({"unchecked", "rawtypes"})
  @Override
  public ByteBuffer toByteBuffer(Object obj) {
    if (obj == null) return null;

    Byte indicator = INDICATOR_BYTES.get(obj.getClass()); // what type is the value?

    if (indicator == null && obj instanceof Serializable)
      indicator = INDICATOR_BYTES.get(Serializable.class);

    if (indicator == null)
      throw new IllegalArgumentException(obj.getClass() + " not serializable by this class");

    byte[] val = ((Serializer) EntityUtils.getSerializer(obj.getClass())).toBytes(obj);
    ByteBuffer buffer = ByteBuffer.allocate(val.length + 1);
    buffer.put(indicator);
    buffer.put(val);
    buffer.rewind();

    return buffer;
  }
示例#8
0
  @Override
  public void upload(
      String koodistoUri, ExportImportFormatType format, String encoding, DataHandler file) {
    try {

      List<KoodiType> koodis = null;
      switch (format) {
        case JHS_XML:
          koodis = koodistoXmlConverter.unmarshal(file, encoding);
          break;
        case CSV:
          koodis = koodistoCsvConverter.unmarshal(file, encoding);
          break;
        case XLS:
          koodis = koodistoXlsConverter.unmarshal(file, encoding);
          break;
        default:
          throw new KoodistoExportException("Unknown koodisto import format.");
      }

      if (koodis == null || koodis.size() == 0) {
        throw new KoodistoExportException("File contained no valid codeElements.");
      }
      List<UpdateKoodiDataType> updateDatas = new ArrayList<UpdateKoodiDataType>();
      for (KoodiType k : koodis) {
        checkIfKoodiHasAllFields(k, koodistoUri);
        UpdateKoodiDataType updateData = new UpdateKoodiDataType();
        EntityUtils.copyFields(k, updateData);

        updateData.getMetadata().addAll(k.getMetadata());
        updateDatas.add(updateData);
      }

      koodiBusinessService.massCreate(koodistoUri, updateDatas);
    } catch (IOException e) {
      throw new KoodistoImportException(e);
    }
  }
示例#9
0
  public BootstrapEntity(PingEntity pingEntity, NodeEntity nodeEntity) {
    super(EntityUtils.getTimeInMillis(pingEntity, nodeEntity), TimeUnit.MILLISECONDS);

    this.pingEntity = pingEntity;
    this.nodeEntity = nodeEntity;
  }
示例#10
0
 public static String getLoggedUserId() {
   return EntityUtils.getEntityId(getLoggedUser());
 }