@Override public ResponseEntity<MgmtSoftwareModuleType> updateSoftwareModuleType( @PathVariable("softwareModuleTypeId") final Long softwareModuleTypeId, @RequestBody final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) { final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.update(entityFactory .softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription()) .colour(restSoftwareModuleType.getColour())); return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType)); }
/** * Finds {@link SoftwareModuleType} in repository with given * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. * * @param key * {@link SoftwareModuleType#getKey()} * @param maxAssignments * {@link SoftwareModuleType#getMaxAssignments()} * * @return persisted {@link SoftwareModuleType} */ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { return softwareModuleTypeManagement.getByKey(key) .orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() .key(key).name(key).description(LOREM.words(10)).maxAssignments(maxAssignments))); }
/** * Finds {@link SoftwareModuleType} in repository with given * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. * * @param key * {@link SoftwareModuleType#getKey()} * @param maxAssignments * {@link SoftwareModuleType#getMaxAssignments()} * * @return persisted {@link SoftwareModuleType} */ public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { return softwareModuleTypeManagement.getByKey(key) .orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() .key(key).name(key).description(LOREM.words(10)).maxAssignments(maxAssignments))); }
private static SoftwareModuleTypeCreate fromRequest(final EntityFactory entityFactory, final MgmtSoftwareModuleTypeRequestBodyPost smsRest) { return entityFactory.softwareModuleType().create().key(smsRest.getKey()).name(smsRest.getName()) .description(smsRest.getDescription()).colour(smsRest.getColour()) .maxAssignments(smsRest.getMaxAssignments()); }
@Before public void before() throws Exception { final String description = "Updated description."; osType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS)); osType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(osType.getId()).description(description))); appType = securityRule.runAsPrivileged( () -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE)); appType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(appType.getId()).description(description))); runtimeType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT)); runtimeType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(runtimeType.getId()).description(description))); standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType()); // publish the reset counter market event to reset the counters after // setup. The setup is transparent by the test and its @ExpectedEvent // counting so we reset the counter here after the setup. Note that this // approach is only working when using a single-thread executor in the // ApplicationEventMultiCaster which the TestConfiguration is doing so // the order of the events keep the same. EventVerifier.publishResetMarkerEvent(eventPublisher); }
@Before public void before() throws Exception { final String description = "Updated description."; osType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_OS)); osType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(osType.getId()).description(description))); appType = securityRule.runAsPrivileged( () -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_APP, Integer.MAX_VALUE)); appType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(appType.getId()).description(description))); runtimeType = securityRule .runAsPrivileged(() -> testdataFactory.findOrCreateSoftwareModuleType(TestdataFactory.SM_TYPE_RT)); runtimeType = securityRule.runAsPrivileged(() -> softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(runtimeType.getId()).description(description))); standardDsType = securityRule.runAsPrivileged(() -> testdataFactory.findOrCreateDefaultTestDsType()); // publish the reset counter market event to reset the counters after // setup. The setup is transparent by the test and its @ExpectedEvent // counting so we reset the counter here after the setup. Note that this // approach is only working when using a single-thread executor in the // ApplicationEventMultiCaster which the TestConfiguration is doing so // the order of the events keep the same. EventVerifier.publishResetMarkerEvent(eventPublisher); }
private void updateSWModuleType(final SoftwareModuleType existingType) { getSoftwareModuleTypeManagement().update(getEntityFactory().softwareModuleType().update(existingType.getId()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()))); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", existingType.getName())); getEventBus().publish(this, new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE, existingType)); }
private void updateSWModuleType(final SoftwareModuleType existingType) { getSoftwareModuleTypeManagement().update(getEntityFactory().softwareModuleType().update(existingType.getId()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()))); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", existingType.getName())); getEventBus().publish(this, new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.UPDATE_SOFTWARE_MODULE_TYPE, existingType)); }
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Handles the DELETE request for a single software module Type within SP. Required Permission: DELETE_REPOSITORY.") public void deleteSoftwareModuleType() throws Exception { final SoftwareModuleType testType = softwareModuleTypeManagement.create( entityFactory.softwareModuleType().create().key("test1").name("TestName1").description("Desc1")); assertThat(softwareModuleTypeManagement.count()).isEqualTo(4); this.mockMvc .perform(delete(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING + "/{softwareModuleTypeID}", testType.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(pathParameters( parameterWithName("softwareModuleTypeID").description(ApiModelPropertiesGeneric.ITEM_ID)))); assertThat(softwareModuleTypeManagement.count()).isEqualTo(3); }
private void createNewSWModuleType() { int assignNumber = 0; final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final String assignValue = (String) getAssignOptiongroup().getValue(); if (assignValue != null && assignValue.equalsIgnoreCase(getSingleAssignStr())) { assignNumber = 1; } else if (assignValue != null && assignValue.equalsIgnoreCase(getMultiAssignStr())) { assignNumber = Integer.MAX_VALUE; } if (typeNameValue != null && typeKeyValue != null) { final SoftwareModuleType newSWType = getSoftwareModuleTypeManagement() .create(getEntityFactory().softwareModuleType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).maxAssignments(assignNumber)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newSWType.getName())); getEventBus().publish(this, new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE, newSWType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
private void createNewSWModuleType() { int assignNumber = 0; final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final String assignValue = (String) getAssignOptiongroup().getValue(); if (assignValue != null && assignValue.equalsIgnoreCase(getSingleAssignStr())) { assignNumber = 1; } else if (assignValue != null && assignValue.equalsIgnoreCase(getMultiAssignStr())) { assignNumber = Integer.MAX_VALUE; } if (typeNameValue != null && typeKeyValue != null) { final SoftwareModuleType newSWType = getSoftwareModuleTypeManagement() .create(getEntityFactory().softwareModuleType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).maxAssignments(assignNumber)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newSWType.getName())); getEventBus().publish(this, new SoftwareModuleTypeEvent(SoftwareModuleTypeEnum.ADD_SOFTWARE_MODULE_TYPE, newSWType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Handles the GET request of retrieving all software module types within SP with parametsrs. In this case the first 10 result in ascending order by name wher the name starts with 'a'. Required Permission: READ_REPOSITORY.") public void getSoftwareModuleTypesWithParameters() throws Exception { final SoftwareModuleType testType = testdataFactory.findOrCreateSoftwareModuleType("test123"); softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234")); mockMvc.perform(get( MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING + "?limit=10&sort=name:ASC&offset=0&q=name==a") .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(getFilterRequestParamter())); }
public void postSoftwareModuleTypes() throws Exception { final List<SoftwareModuleType> types = Arrays.asList(entityFactory.softwareModuleType().create().key("test1") .name("TestName1").description("Desc1").build());
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Handles the GET request of retrieving all software module types within SP. Required Permission: READ_REPOSITORY.") public void getSoftwareModuleTypes() throws Exception { final SoftwareModuleType testType = testdataFactory.findOrCreateSoftwareModuleType("test123"); softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234")); mockMvc.perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andDo(this.document.document(responseFields( fieldWithPath("size").type(JsonFieldType.NUMBER).description(ApiModelPropertiesGeneric.SIZE), fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS), fieldWithPath("content").description(MgmtApiModelProperties.TARGET_LIST), fieldWithPath("content[].createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("content[].createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("content[].description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("content[].id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("content[].lastModifiedAt") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"), fieldWithPath("content[].lastModifiedBy") .description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"), fieldWithPath("content[].name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("content[]._links.self").ignored()))); }
@Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Handles the GET request of retrieving a single software module type within SP. Required Permission: READ_REPOSITORY.") public void getSoftwareModuleType() throws Exception { final SoftwareModuleType testType = testdataFactory.findOrCreateSoftwareModuleType("test123"); softwareModuleTypeManagement .update(entityFactory.softwareModuleType().update(testType.getId()).description("Desc1234")); this.mockMvc .perform(get(MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING + "/{softwareModuleTypeID}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andDo(this.document.document( pathParameters(parameterWithName("softwareModuleTypeID") .description(ApiModelPropertiesGeneric.ITEM_ID)), responseFields(fieldWithPath("key").description(MgmtApiModelProperties.SMT_KEY), fieldWithPath("maxAssignments").description(MgmtApiModelProperties.SMT_MAX_ASSIGNMENTS), fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY), fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT), fieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION), fieldWithPath("deleted").description(ApiModelPropertiesGeneric.DELETED), fieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID), fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT) .type("Number"), fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY) .type("String"), fieldWithPath("name").description(ApiModelPropertiesGeneric.NAME), fieldWithPath("_links.self").ignored()))); }