/** * {@inheritDoc} * */ @SuppressWarnings("unchecked") @Override public void execute(IStorageService storageService) throws BusinessException { if (isLabelTypeBasedAction()) { List<?> returnList = storageService.getLabelSuggestions(this.getLabelType()); List<AbstractStorageLabel<?>> labels = (List<AbstractStorageLabel<?>>) returnList; storageService.removeLabelsFromCmr(labels, this.isRemoveFromStorageAlso()); storageService.removeLabelType(this.getLabelType()); } else if (isLabelBasedAction()) { Collection<AbstractStorageLabel<?>> labels = this.getLabelList(); storageService.removeLabelsFromCmr(labels, this.isRemoveFromStorageAlso()); } }
@ResponseBody public Map<String, Object> getRecordingState() { RecordingState state = storageService.getRecordingState(); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("recordingState", state); if (RecordingState.OFF != state) { RecordingData recordingData = storageService.getRecordingData(); resultMap.put("recordingStorage", recordingData.getRecordingStorage());
/** * Finalize storage by ID. * <p> * <i> Example URL: /storage/{id}/finalize</i> * * @param id * ID bounded from path. * @throws BusinessException * If {@link BusinessException} occurs. * @return Message for the user. */ @RequestMapping(method = GET, value = "{id}/finalize") @ResponseBody public Object finalizeStorage(@PathVariable String id) throws BusinessException { StorageData storageData = new StorageData(); storageData.setId(id); storageService.closeStorage(storageData); return Collections.singletonMap("message", "Storage id " + id + " successfully finalized."); }
/** * {@inheritDoc} */ @Override public void execute(IStorageService storageService) { if (isLabelTypeBasedAction()) { storageService.saveLabelType(this.getLabelType()); } else if (isLabelBasedAction()) { for (AbstractStorageLabel<?> label : this.getLabelList()) { storageService.saveLabelToCmr(label); } } }
/** * Refreshes the recording state. */ public void refreshRecordingState() { if (onlineStatus == OnlineStatus.ONLINE) { try { RecordingState state = getStorageService().getRecordingState(); recordingState = state; } catch (Exception e) { recordingState = RecordingState.OFF; } } else { recordingState = RecordingState.OFF; } }
@SuppressWarnings("deprecation") @Test public void startRecording() throws BusinessException { String id = "id"; StorageData storageData = new StorageData(); storageData.setId(id); when(storageService.getExistingStorages()).thenReturn(Collections.singletonList(storageData)); restfulService.startOrScheduleRecording(id, 10L, 20L, true, true); ArgumentCaptor<RecordingProperties> propertiesCaptor = ArgumentCaptor.forClass(RecordingProperties.class); verify(storageService, times(1)).startOrScheduleRecording(eq(storageData), propertiesCaptor.capture()); assertThat(propertiesCaptor.getValue().getStartDelay(), is(10L)); assertThat(propertiesCaptor.getValue().getRecordDuration(), is(20L)); assertThat(propertiesCaptor.getValue().isAutoFinalize(), is(true)); assertThat(propertiesCaptor.getValue().getRecordingDataProcessors(), hasItem(is(InvocationExtractorDataProcessor.class))); restfulService.startOrScheduleRecording(id, 10L, 20L, false, false); verify(storageService, times(2)).startOrScheduleRecording(eq(storageData), propertiesCaptor.capture()); assertThat(propertiesCaptor.getValue().isAutoFinalize(), is(false)); assertThat(propertiesCaptor.getValue().getRecordingDataProcessors(), not(hasItem(is(InvocationExtractorDataProcessor.class)))); } }
suggestionLabelList.addAll(cmrRepositoryDefinition.getStorageService().getLabelSuggestions(label.getStorageLabelType())); if (!suggestionLabelList.isEmpty() && (null != storageData)) { suggestionLabelList.removeAll(storageData.getLabelList());
/** * Returns all storages. * <p> * <i> Example URL: /storage</i> * * @return List of all storages. */ @RequestMapping(method = GET, value = "") @ResponseBody public List<StorageData> getAllStorages() { List<StorageData> storages = storageService.getExistingStorages(); return storages; }
/** * Deletes storage by ID. * <p> * <i> Example URL: /storage/{id}/delete</i> * * @param id * ID bounded from path. * @throws BusinessException * If {@link BusinessException} occurs. * @return Message for the user. */ @RequestMapping(method = GET, value = "{id}/delete") @ResponseBody public Object deleteStorage(@PathVariable String id) throws BusinessException { StorageData storageData = new StorageData(); storageData.setId(id); storageService.deleteStorage(storageData); return Collections.singletonMap("message", "Storage id " + id + " successfully deleted."); }
/** * Creates a new storage with given name. * <p> * <i> Example URL: /storage/{name}/create</i> * * @param name * Name of the storage. * @return Map containing message and created storage. * @throws BusinessException * If {@link BusinessException} occurs. */ @RequestMapping(method = GET, value = "{name}/create") @ResponseBody public Object createStorage(@PathVariable String name) throws BusinessException { if (StringUtils.isEmpty(name)) { throw new BusinessException("Create a new storage via storage REST service.", StorageErrorCodeEnum.STORAGE_NAME_IS_NOT_PROVIDED); } StorageData storageData = new StorageData(); storageData.setName(name); storageData = storageService.createAndOpenStorage(storageData); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("message", "Storage successfully created."); resultMap.put("storage", storageData); return resultMap; }
/** * Add label. */ @Test public void addLabelAction() { AbstractStorageLabel<?> label = mock(AbstractStorageLabel.class); addLabelManagementAction = new AddLabelManagementAction(Collections.<AbstractStorageLabel<?>> singletonList(label)); addLabelManagementAction.execute(storageService); verify(storageService, times(1)).saveLabelToCmr(label); verifyNoMoreInteractions(storageService); }
/** * Remove label. */ @Test public void removeLabelAction() throws BusinessException { AbstractStorageLabel<?> label = mock(AbstractStorageLabel.class); removeLabelManagementAction = new RemoveLabelManagementAction(Collections.<AbstractStorageLabel<?>> singletonList(label), false); removeLabelManagementAction.execute(storageService); verify(storageService, times(1)).removeLabelsFromCmr(Collections.<AbstractStorageLabel<?>> singletonList(label), false); removeLabelManagementAction.setRemoveFromStorageAlso(true); removeLabelManagementAction.execute(storageService); verify(storageService, times(1)).removeLabelsFromCmr(Collections.<AbstractStorageLabel<?>> singletonList(label), true); verifyNoMoreInteractions(storageService); }
/** * {@inheritDoc} */ @Override public boolean isPageComplete() { if (getSelectedRepository() == null) { return false; } else if (getSelectedRepository().getOnlineStatus() == OnlineStatus.OFFLINE) { return false; } else if (checkRecording && (getSelectedRepository().getStorageService().getRecordingState() != RecordingState.OFF)) { return false; } if (getSelectedStorageData() == null) { return false; } return true; }
/** * Returns storage by ID. * <p> * <i> Example URL: /storage/{id}</i> * * @param id * ID bounded from path. * @return One storage or <code>null</code> if the storage with given ID does not exists. */ @RequestMapping(method = GET, value = "{id}") @ResponseBody public StorageData getStorageById(@PathVariable String id) { List<StorageData> storages = storageService.getExistingStorages(); for (StorageData storageData : storages) { if (Objects.equals(id, storageData.getId())) { return storageData; } } return null; }
@Test public void deleteStorage() throws BusinessException { String id = "id"; restfulService.deleteStorage(id); ArgumentCaptor<StorageData> captor = ArgumentCaptor.forClass(StorageData.class); verify(storageService, times(1)).deleteStorage(captor.capture()); assertThat(captor.getValue().getId(), is(id)); }
@Test public void createStorage() throws BusinessException { String name = "name"; restfulService.createStorage(name); ArgumentCaptor<StorageData> captor = ArgumentCaptor.forClass(StorageData.class); verify(storageService, times(1)).createAndOpenStorage(captor.capture()); assertThat(captor.getValue().getName(), is(name)); }
/** * Remove label type. */ @SuppressWarnings("unchecked") @Test public void removeLabelTypeAction() throws BusinessException { AbstractStorageLabelType<Object> labelType = mock(AbstractStorageLabelType.class); when(storageService.getLabelSuggestions(labelType)).thenReturn(Collections.<AbstractStorageLabel<Object>> emptyList()); removeLabelManagementAction = new RemoveLabelManagementAction(labelType, false); removeLabelManagementAction.execute(storageService); verify(storageService, times(1)).getLabelSuggestions(labelType); verify(storageService, times(1)).removeLabelType(labelType); verify(storageService, times(1)).removeLabelsFromCmr(Collections.<AbstractStorageLabel<?>> emptyList(), false); verifyNoMoreInteractions(storageService); removeLabelManagementAction.setRemoveFromStorageAlso(true); removeLabelManagementAction.execute(storageService); verify(storageService, times(1)).removeLabelsFromCmr(Collections.<AbstractStorageLabel<?>> emptyList(), true); }
@Test public void recordingStatus() { RecordingData recordingData = mock(RecordingData.class, Mockito.RETURNS_SMART_NULLS); when(storageService.getRecordingData()).thenReturn(recordingData); when(storageService.getRecordingState()).thenReturn(RecordingState.OFF); assertThat(restfulService.getRecordingState(), hasEntry("recordingState", (Object) RecordingState.OFF)); verifyZeroInteractions(recordingData); when(storageService.getRecordingState()).thenReturn(RecordingState.ON); when(recordingData.getRecordEndDate()).thenReturn(new Date()); Map<String, Object> result = restfulService.getRecordingState(); assertThat(result, hasEntry("recordingState", (Object) RecordingState.ON)); assertThat(result, hasKey("recordingStopDate")); when(storageService.getRecordingState()).thenReturn(RecordingState.SCHEDULED); when(recordingData.getRecordStartDate()).thenReturn(new Date()); result = restfulService.getRecordingState(); assertThat(result, hasEntry("recordingState", (Object) RecordingState.SCHEDULED)); assertThat(result, hasKey("schduledStartDate")); }
RecordingState recordingState = cmrRepositoryDefinition.getStorageService().getRecordingState(); if (recordingState == RecordingState.ON) { recordingIcon.setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_RECORD));
@Test public void getStorageById() { String id = "id"; when(storageData.getId()).thenReturn(id); when(storageService.getExistingStorages()).thenReturn(Collections.singletonList(storageData)); assertThat(restfulService.getStorageById(id), is(storageData)); when(storageData.getId()).thenReturn(""); assertThat(restfulService.getStorageById(id), is(nullValue())); }