Skip to content

Commit

Permalink
Removed some options when importing files [#855]
Browse files Browse the repository at this point in the history
Removed the buttons for toggling ignoring metadata and marking blocked
pages as deleted. Instead imports will default to performing those
actions since that's their purpose.
  • Loading branch information
mcpierce committed Sep 19, 2021
1 parent 90c975d commit becd7f9
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 265 deletions.
Expand Up @@ -46,6 +46,8 @@
@Configuration
@Log4j2
public class AddComicsConfiguration {
public static final String PARAM_ADD_COMICS_STARTED = "job.add-comics.started";

@Value("${batch.chunk-size}")
private int batchChunkSize = 10;

Expand Down
Expand Up @@ -39,14 +39,4 @@ public class ImportComicFilesRequest {
@Getter
@Setter
private List<String> filenames = new ArrayList<>();

@JsonProperty("ignoreMetadata")
@Getter
@Setter
private boolean ignoreMetadata;

@JsonProperty("deleteBlockedPages")
@Getter
@Setter
private boolean deleteBlockedPages;
}
Expand Up @@ -26,6 +26,7 @@
import org.comixedproject.adaptors.archive.ArchiveAdaptorException;
import org.comixedproject.adaptors.handlers.ComicFileHandlerException;
import org.comixedproject.auditlog.AuditableEndpoint;
import org.comixedproject.batch.comicbooks.AddComicsConfiguration;
import org.comixedproject.model.net.GetAllComicsUnderRequest;
import org.comixedproject.model.net.ImportComicFilesRequest;
import org.comixedproject.model.net.comicfiles.LoadComicFilesResponse;
Expand Down Expand Up @@ -54,7 +55,6 @@
@RequestMapping("/api/files")
@Log4j2
public class ComicFileController {
private static final String KEY_ADD_COMICS_STARTED = "key.add-comics.started";

@Autowired private ComicFileService comicFileService;

Expand Down Expand Up @@ -147,16 +147,14 @@ public void importComicFiles(@RequestBody() ImportComicFilesRequest request)
throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException,
JobParametersInvalidException, JobRestartException {
final List<String> filenames = request.getFilenames();
final boolean deleteBlockedPages = request.isDeleteBlockedPages();
final boolean ignoreMetadata = request.isIgnoreMetadata();

log.info("Importing comic files");
this.comicFileService.importComicFiles(filenames);
log.trace("Launching add comics process");
this.jobLauncher.run(
addComicsToLibraryJob,
new JobParametersBuilder()
.addLong(KEY_ADD_COMICS_STARTED, System.currentTimeMillis())
.addLong(AddComicsConfiguration.PARAM_ADD_COMICS_STARTED, System.currentTimeMillis())
.toJobParameters());
}
}
Expand Up @@ -50,8 +50,6 @@ public class ComicFileControllerTest {
private static final String TEST_DIRECTORY = "src/test";
private static final Integer TEST_LIMIT = RANDOM.nextInt();
private static final Integer TEST_NO_LIMIT = -1;
private static final boolean TEST_DELETE_BLOCKED_PAGES = RANDOM.nextBoolean();
private static final boolean TEST_IGNORE_METADATA = RANDOM.nextBoolean();

@InjectMocks private ComicFileController controller;
@Mock private ComicFileService comicFileService;
Expand Down Expand Up @@ -124,8 +122,7 @@ public void testImportComicFiles() throws Exception {
Mockito.when(jobLauncher.run(Mockito.any(Job.class), jobParametersArgumentCaptor.capture()))
.thenReturn(jobExecution);

controller.importComicFiles(
new ImportComicFilesRequest(filenameList, TEST_IGNORE_METADATA, TEST_DELETE_BLOCKED_PAGES));
controller.importComicFiles(new ImportComicFilesRequest(filenameList));

final JobParameters jobParameters = jobParametersArgumentCaptor.getValue();

Expand Down
Expand Up @@ -23,8 +23,6 @@ export const sendComicFiles = createAction(
'[Import Comic Files] Begin importing the selected comic files',
props<{
files: ComicFile[];
ignoreMetadata: boolean;
deleteBlockedPages: boolean;
}>()
);

Expand Down
Expand Up @@ -32,50 +32,6 @@
>
<mat-icon>check_box_outline_blank</mat-icon>
</button>
<button
*ngIf="ignoreMetadata"
id="ignore-metadata-button"
class="cx-margin-right-5"
mat-icon-button
color="primary"
[matTooltip]="'comic-files.tooltip.ignore-metadata-on' | translate"
(click)="onToggleIgnoreMetadata()"
>
<mat-icon>block</mat-icon>
</button>
<button
*ngIf="!ignoreMetadata"
id="use-metadata-button"
class="cx-margin-right-5"
mat-icon-button
color="primary"
[matTooltip]="'comic-files.tooltip.ignore-metadata-off' | translate"
(click)="onToggleIgnoreMetadata()"
>
<mat-icon>remove_circle_outline</mat-icon>
</button>
<button
*ngIf="deleteBlockedPages"
id="cx-delete-blocked-pages-button"
class="cx-margin-right-5"
mat-icon-button
color="primary"
[matTooltip]="'comic-files.tooltip.delete-blocked-pages-on' | translate"
(click)="onToggleDeleteBlockedPages()"
>
<mat-icon>delete</mat-icon>
</button>
<button
*ngIf="!deleteBlockedPages"
id="cx-ignore-blocked-pages-button"
class="cx-margin-right-5"
mat-icon-button
color="primary"
[matTooltip]="'comic-files.tooltip.delete-blocked-pages-off' | translate"
(click)="onToggleDeleteBlockedPages()"
>
<mat-icon>clear</mat-icon>
</button>
<button
id="start-import-button"
class="cx-margin-right-5"
Expand Down
Expand Up @@ -147,49 +147,16 @@ describe('ComicFileToolbarComponent', () => {
});
});

describe('toggling the ignore metadata flag', () => {
const IGNORED = Math.random() > 0.5;

beforeEach(() => {
component.ignoreMetadata = IGNORED;
component.onToggleIgnoreMetadata();
});

it('flips the flag', () => {
expect(component.ignoreMetadata).not.toEqual(IGNORED);
});
});

describe('marking blocked pages for deletion', () => {
const MARKED = Math.random() > 0.5;

beforeEach(() => {
component.deleteBlockedPages = MARKED;
component.onToggleDeleteBlockedPages();
});

it('flips the flag', () => {
expect(component.deleteBlockedPages).not.toEqual(MARKED);
});
});

describe('starting the import process', () => {
const IGNORED = Math.random() > 0.5;
const MARKED = Math.random() > 0.5;

beforeEach(() => {
component.ignoreMetadata = IGNORED;
component.deleteBlockedPages = MARKED;
component.selectedComicFiles = COMIC_FILES;
component.onStartImport();
});

it('fires an action', () => {
expect(store.dispatch).toHaveBeenCalledWith(
sendComicFiles({
files: COMIC_FILES,
ignoreMetadata: IGNORED,
deleteBlockedPages: MARKED
files: COMIC_FILES
})
);
});
Expand Down
Expand Up @@ -42,8 +42,6 @@ import { User } from '@app/user/models/user';
styleUrls: ['./comic-file-toolbar.component.scss']
})
export class ComicFileToolbarComponent {
@Input() ignoreMetadata = false;
@Input() deleteBlockedPages = false;
@Input() comicFiles: ComicFile[] = [];
@Input() selectedComicFiles: ComicFile[] = [];

Expand Down Expand Up @@ -111,26 +109,11 @@ export class ComicFileToolbarComponent {
this.store.dispatch(clearComicFileSelections());
}

onToggleIgnoreMetadata(): void {
this.logger.trace('Setting ignoring metadata to', !this.ignoreMetadata);
this.ignoreMetadata = this.ignoreMetadata === false;
}

onToggleDeleteBlockedPages(): void {
this.logger.trace(
'Setting deleting blocked pages to',
!this.deleteBlockedPages
);
this.deleteBlockedPages = this.deleteBlockedPages === false;
}

onStartImport(): void {
this.logger.trace('Starting the import process');
this.store.dispatch(
sendComicFiles({
files: this.selectedComicFiles,
ignoreMetadata: this.ignoreMetadata,
deleteBlockedPages: this.deleteBlockedPages
files: this.selectedComicFiles
})
);
}
Expand Down
Expand Up @@ -37,11 +37,6 @@ import {
sendComicFiles,
sendComicFilesFailed
} from '@app/comic-file/actions/import-comic-files.actions';
import { saveUserPreference } from '@app/user/actions/user.actions';
import {
DELETE_BLOCKED_PAGES_PREFERENCE,
IGNORE_METADATA_PREFERENCE
} from '@app/library/library.constants';
import { hot } from 'jasmine-marbles';
import { clearComicFileSelections } from '@app/comic-file/actions/comic-file-list.actions';

Expand Down Expand Up @@ -88,35 +83,22 @@ describe('ImportComicFilesEffects', () => {
});

describe('sending comic files', () => {
const IGNORE_METADATA = Math.random() > 0.5;
const DELETE_BLOCKED_PAGES = Math.random() > 0.5;

it('fires an action on success', () => {
const serviceResponse = new HttpResponse({ status: 200 });
const action = sendComicFiles({
files: FILES,
ignoreMetadata: IGNORE_METADATA,
deleteBlockedPages: DELETE_BLOCKED_PAGES
files: FILES
});
const outcome1 = comicFilesSent();
const outcome2 = clearComicFileSelections();
const outcome3 = saveUserPreference({
name: IGNORE_METADATA_PREFERENCE,
value: `${IGNORE_METADATA}`
});
const outcome4 = saveUserPreference({
name: DELETE_BLOCKED_PAGES_PREFERENCE,
value: `${DELETE_BLOCKED_PAGES}`
});

actions$ = hot('-a', { a: action });
comicImportService.sendComicFiles.and.returnValue(of(serviceResponse));
comicImportService.sendComicFiles
.withArgs({ files: FILES })
.and.returnValue(of(serviceResponse));

const expected = hot('-(bcde)', {
const expected = hot('-(bc)', {
b: outcome1,
c: outcome2,
d: outcome3,
e: outcome4
c: outcome2
});
expect(effects.sendComicFiles$).toBeObservable(expected);
expect(alertService.info).toHaveBeenCalledWith(jasmine.any(String));
Expand All @@ -125,16 +107,14 @@ describe('ImportComicFilesEffects', () => {
it('fires an action on service failure', () => {
const serviceResponse = new HttpErrorResponse({});
const action = sendComicFiles({
files: FILES,
ignoreMetadata: false,
deleteBlockedPages: true
files: FILES
});
const outcome = sendComicFilesFailed();

actions$ = hot('-a', { a: action });
comicImportService.sendComicFiles.and.returnValue(
throwError(serviceResponse)
);
comicImportService.sendComicFiles
.withArgs({ files: FILES })
.and.returnValue(throwError(serviceResponse));

const expected = hot('-b', { b: outcome });
expect(effects.sendComicFiles$).toBeObservable(expected);
Expand All @@ -143,14 +123,14 @@ describe('ImportComicFilesEffects', () => {

it('fires an action on general failure', () => {
const action = sendComicFiles({
files: FILES,
ignoreMetadata: false,
deleteBlockedPages: true
files: FILES
});
const outcome = sendComicFilesFailed();

actions$ = hot('-a', { a: action });
comicImportService.sendComicFiles.and.throwError('expected');
comicImportService.sendComicFiles
.withArgs({ files: FILES })
.and.throwError('expected');

const expected = hot('-(b|)', { b: outcome });
expect(effects.sendComicFiles$).toBeObservable(expected);
Expand Down
Expand Up @@ -26,11 +26,6 @@ import {
sendComicFiles,
sendComicFilesFailed
} from '@app/comic-file/actions/import-comic-files.actions';
import { saveUserPreference } from '@app/user/actions/user.actions';
import {
DELETE_BLOCKED_PAGES_PREFERENCE,
IGNORE_METADATA_PREFERENCE
} from '@app/library/library.constants';
import { LoggerService } from '@angular-ru/logger';
import { ComicImportService } from '@app/comic-file/services/comic-import.service';
import { AlertService } from '@app/core/services/alert.service';
Expand All @@ -46,9 +41,7 @@ export class ImportComicFilesEffects {
switchMap(action =>
this.comicImportService
.sendComicFiles({
files: action.files,
ignoreMetadata: action.ignoreMetadata,
deleteBlockedPages: action.deleteBlockedPages
files: action.files
})
.pipe(
tap(response => this.logger.debug('Response received:', response)),
Expand All @@ -60,18 +53,7 @@ export class ImportComicFilesEffects {
)
)
),
mergeMap(() => [
comicFilesSent(),
clearComicFileSelections(),
saveUserPreference({
name: IGNORE_METADATA_PREFERENCE,
value: `${action.ignoreMetadata}`
}),
saveUserPreference({
name: DELETE_BLOCKED_PAGES_PREFERENCE,
value: `${action.deleteBlockedPages}`
})
]),
mergeMap(() => [comicFilesSent(), clearComicFileSelections()]),
catchError(error => {
this.logger.error('Service failure:', error);
this.alertService.error(
Expand Down

0 comments on commit becd7f9

Please sign in to comment.