Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2058 moved unit measurement definitions to backend #2905

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,22 @@ public String getFittingUnits(UnitDescription unitDescription) throws AdapterExc
return gson.toJson(unitDescriptionList);
}

public List<UnitDescription> getAllUnitDescriptions(){
List<UnitDescription> unitDescriptionList = new LinkedList<>();

List<Unit> units = UnitProvider.INSTANCE.getAvailableUnits();

for (Unit unit : units) {
try {
UnitDescription unitDescriptionTmp =
new UnitDescription(unit.getResource().toString(), unit.getLabel());
unitDescriptionList.add(unitDescriptionTmp);
} catch (NullPointerException e) {
logger.error("Unit has no resource and/or Label");
}
}

return unitDescriptionList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v2/connect/master/unit")
public class UnitResource extends AbstractAdapterResource<UnitMasterManagement> {
Expand All @@ -55,4 +58,11 @@ public ResponseEntity<?> getFittingUnits(@RequestBody UnitDescription unitDescri
}
}

@GetMapping(path = "/units",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<UnitDescription>> getAllUnits(){
List<UnitDescription> unitDescriptions = managementService.getAllUnitDescriptions();
return ok(unitDescriptions);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { UnitDescription } from '../../../../model/UnitDescription';
import { RestService } from '../../../../services/rest.service';
import { UnitProviderService } from '../../../../services/unit-provider.service';
import { EventPropertyPrimitive } from '@streampipes/platform-services';

@Component({
Expand Down Expand Up @@ -50,19 +49,23 @@ export class EditUnitTransformationComponent implements OnInit {
newUnitStateCtrl = new UntypedFormControl();
filteredUnits: Observable<UnitDescription[]>;

constructor(
private restService: RestService,
private unitProviderService: UnitProviderService,
) {
this.allUnits = this.unitProviderService
.getUnits()
.sort((a, b) => a.label.localeCompare(b.label));
this.filteredUnits = this.currentUnitStateCtrl.valueChanges.pipe(
startWith(''),
map(unit =>
unit ? this._filteredUnits(unit) : this.allUnits.slice(),
),
);
constructor(private restService: RestService) {
this.restService
.getAllUnitDescriptions()
.subscribe((unitDescriptions: UnitDescription[]) => {
unitDescriptions.sort((a, b) => a.label.localeCompare(b.label));
this.allUnits = unitDescriptions;
this.filteredUnits =
this.currentUnitStateCtrl.valueChanges.pipe(
startWith(''),
map(unit =>
unit
? this._filteredUnits(unit)
: this.allUnits.slice(),
),
);
});

this.currentUnitStateCtrl.valueChanges.subscribe(val => {
const unitResource =
val === '' ? undefined : this.findUnitByLabel(val).resource;
Expand Down
9 changes: 9 additions & 0 deletions ui/src/app/connect/services/rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,13 @@ export class RestService {
}),
);
}

getAllUnitDescriptions(): Observable<UnitDescription[]> {
return this.http.get(`${this.connectPath}/master/unit/units`).pipe(
map(response => {
const descriptions = response as UnitDescription[];
return descriptions;
}),
);
}
}
Loading
Loading