示例#1
0
 /** creates a KimTypeAttribute from an existing {@link KimTypeAttributeContract}. */
 public static Builder create(KimTypeAttributeContract contract) {
   Builder builder = new Builder();
   builder.setId(contract.getId());
   builder.setSortCode(contract.getSortCode());
   if (contract.getKimAttribute() != null) {
     builder.setKimAttribute(KimAttribute.Builder.create(contract.getKimAttribute()));
   }
   builder.setKimTypeId(contract.getKimTypeId());
   builder.setActive(contract.isActive());
   builder.setVersionNumber(contract.getVersionNumber());
   builder.setObjectId(contract.getObjectId());
   return builder;
 }
  @Test
  public void testCreateGroupWithCustomKimTypeAttributes() {
    // This test needs to be run in separate test class
    // with @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
    KimAttribute.Builder kimAttribute =
        KimAttribute.Builder.create(KIM_ATTRIBUTE_COMPONENT_NAME, KIM_ATTRIBUTE_NAME, NAMESPACE);
    kimAttribute.setAttributeLabel(KIM_ATTRIBUTE_LABEL);
    kimAttribute.setId(KIM_ATTRIBUTE_ID);
    kimAttribute.setActive(true);
    KimAttributeBo kimAddrBo =
        KRADServiceLocator.getDataObjectService().save(KimAttributeBo.from(kimAttribute.build()));

    KimType.Builder kimTypeBuilder = KimType.Builder.create();
    kimTypeBuilder.setId(KIM_TYPE_ID);
    kimTypeBuilder.setName(KIM_TYPE_NAME);
    kimTypeBuilder.setNamespaceCode(NAMESPACE);
    kimTypeBuilder.setServiceName(KIM_TYPE_SERVICE_NAME);
    kimTypeBuilder.setActive(true);
    KimTypeBo kimTypeBo =
        KRADServiceLocator.getDataObjectService().save(KimTypeBo.from(kimTypeBuilder.build()));

    KimTypeAttribute.Builder kimTypeAttributeBuilder = KimTypeAttribute.Builder.create();
    kimTypeAttributeBuilder.setId(KIM_TYPE_ATTRIBUTE_ID);
    kimTypeAttributeBuilder.setActive(true);
    kimTypeAttributeBuilder.setSortCode("a");
    kimTypeAttributeBuilder.setKimTypeId(KIM_TYPE_ID);
    kimTypeAttributeBuilder.setKimAttribute(kimAttribute);
    KimTypeAttributeBo kimTypeAttrBo =
        KRADServiceLocator.getDataObjectService()
            .save(KimTypeAttributeBo.from(kimTypeAttributeBuilder.build()));

    kimTypeBuilder =
        KimType.Builder.create(
            KimApiServiceLocator.getKimTypeInfoService().getKimType(KIM_TYPE_ID));
    kimTypeAttributeBuilder = KimTypeAttribute.Builder.create(kimTypeAttrBo);
    List<KimTypeAttribute.Builder> attrList = Collections.singletonList(kimTypeAttributeBuilder);
    kimTypeBuilder.setAttributeDefinitions(attrList);

    kimTypeBo =
        KRADServiceLocator.getDataObjectService().save(KimTypeBo.from(kimTypeBuilder.build()));
    KRADServiceLocator.getDataObjectService().flush(KimTypeBo.class);

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put(KIM_ATTRIBUTE_NAME, KIM_ATTRIBUTE_VALUE);

    Group.Builder groupInfo = Group.Builder.create(NAMESPACE, GROUP_NAME, KIM_TYPE_ID);
    groupInfo.setAttributes(attributes);
    groupInfo.setActive(true);
    groupInfo.setDescription(KIM_ATTRIBUTE_LABEL + " " + KIM_ATTRIBUTE_VALUE);
    Group group = KimApiServiceLocator.getGroupService().createGroup(groupInfo.build());

    Group result =
        KimApiServiceLocator.getGroupService()
            .getGroupByNamespaceCodeAndName(NAMESPACE, GROUP_NAME);
    assertEquals(groupInfo.isActive(), result.isActive());
    assertTrue(groupInfo.getNamespaceCode().equals(result.getNamespaceCode()));
    assertTrue(groupInfo.getName().equals(result.getName()));
    assertTrue(groupInfo.getKimTypeId().equals(result.getKimTypeId()));
    assertEquals(1, result.getAttributes().size());
    assertTrue(result.getAttributes().get(KIM_ATTRIBUTE_NAME).contains(KIM_ATTRIBUTE_VALUE));
  }